1.0.2 • Published 5 years ago
uni-ls v1.0.2
install
NPM
npm install uni-ls --saveYARN
yarn add uni-lsUsage
uni storage API
import Storage from "uni-ls";
// name 默认 ls;
Vue.use(Storage, { name: "ls" });
// or
Vue.use(Storage);
// 实例化存储
const config = {
version: "0.0.1", // 当前存储版本号 推荐动态读取manifest.json文件版本名称(versionName)
namespace: "__ls__", // 当前存储key前缀 推荐动态读取manifest.json文件中AppID(appid)
}
const storage = new Storage();
export default storage; // 方便js文件内直接使用
new Vue({
el: '#app',
created() {
Vue.ls.set('foo', 'boo');
//Set expire for item
Vue.ls.set('foo', 'boo', 60 * 60); //expiry 1 hour
Vue.ls.get('foo');
Vue.ls.remove('foo');
},
})Context
this.$lsAPI
Vue.ls.get(name, version);返回key为name的本地存储数据。
version默认为0.0.1,返回大于当前版本数据小于当前版本数据会自动删除
Vue.ls.set(name, value, expire);存储name下的value。
expire默认null,数据有效秒
Vue.ls.getAll(version)返回所以存储数据
version默认为0.0.1,返回大于当前版本数据小于当前版本数据会自动删除
Vue.ls.remove(name);删除name数据,成功返回true;
Vue.ls.on(name, callback);添加name发生变化时的监听
Vue.ls.off(name, callback);关闭name发生变化的回调
callback不填写清空当前name的所有监听事件