(十六)Vue-ls存储缓存,比如存用户信息等
1:安装Vue-ls
npm install vue-ls --save
2.在main.js里面引用vue-ls
import Storage from 'vue-ls';
3.设置Storage的option操作
storageOptions: {
namespace: 'pro__',
name: 'ls',
storage: 'local'
},
4:在main.js里面挂载Storage
app.use(Storage, options);
5:在main.js所在的页面就可以使用app.ls了
app.ls.set('foo', 'boo'); //设置缓存
app.ls.get('foo', 'boo'); //获取缓存
6:如果要在其他页面也使用可以在main.js里面设置一个全局变量
app.config.globalProperties.appls=app.ls;//this.appls.get不能在main.js引用的js里面使用,只能在其他页面使用
其他地方就可以通过
alert(this.appls.get('foo'))来使用appls了
通过if (tthis.appls.get('foo'))判断too是否有值