vue.js和good-storage缓存

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
原文地址:https://www.cnblogs.com/zgxblog/p/11661283.html