封装localstorage方法

 1 //封装操作localstorage本地存储的方法
 2 
 3 var storage = {
 4 
 5 //存储
 6 set(key, value) {
 7 localStorage.setItem(key, JSON.stringify(value));
 8 },
 9 //取出数据
10 get(key) {
11 return JSON.parse(localStorage.getItem(key));
12 },
13 // 删除数据
14 remove(key) {
15 localStorage.removeItem(key);
16 }
17 
18 }
19 
20 // 暴露给外部访问
21 export default storage;


猜你喜欢

转载自www.cnblogs.com/sunery/p/10114695.html