VUE.JS 缓存 good-storage :

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

localStorage 临时缓存(关闭浏览器自动销毁)

sessionStorage 长期缓存(主动清楚缓存才会销毁)

安装步骤:

在命令行安装

npm install good-storage

使用:

 1 import storage from 'good-storage'
 2 
 3 // localStorage
 4 storage.set(key,val) 
 5 
 6 storage.get(key, def)
 7 
 8 // sessionStorage
 9 storage.session.set(key, val)
10 
11 storage.session.get(key, val)
12 缓存的API
13 
14 set(key, val)
15 set storage with key and val
16 
17 get(key, def)
18 get storage with key, return def if not find
19 
20 remove(key)
21 remove storage with key
22 
23 has(key)
24 determine storage has the key
25 
26 clear()
27 clear all storages
28 
29 getAll()
30 get all the storages
31 
32 forEach(callback)
33 forEach the storages and call the callback function with each storage

 

posted on 2019-10-12 14:14  鸥海  阅读(1720)  评论(0编辑  收藏  举报