VUE 缓存 设置缓存 使用缓存

文章来源:华科小宝   作者:赵苗     发布时间:2021-03-31 10:50    浏览量:

VUE.JS 使用缓存我建议用 good-storage ,简单方便好用,下面来看看怎么使用它

 

good-storage 是一个插件,需要安装

 

localStorage 临时缓存(主动清除缓存才会销毁)

 

sessionStorage 长期缓存(关闭浏览器自动销毁)

 

安装步骤:

在命令行安装

npm install good-storage

使用:

   import storage from 'good-storage'

   // localStorage

 storage.set(key,val)

   storage.get(key, def)

 // sessionStorage

  storage.session.set(key, val)

 storage.session.get(key, val)

缓存的API

set(key, val)

set storage with key and val

 

get(key, def)

get storage with key, return def if not find

 

remove(key)

remove storage with key

 

has(key)

determine storage has the key

 

clear()

clear all storages

 

getAll()

get all the storages

 

forEach(callback)

forEach the storages and call the callback function with each storage


甘肃华科信息技术有限责任公司    版权所有    陇ICP备17001897-1号   甘公网安备 62010202001329 号