vue-ls

作者: Cherry丶小丸子 | 来源:发表于2022-06-13 13:55 被阅读0次

https://blog.csdn.net/CEZLZ/article/details/108147697
https://github.com/RobinCK/vue-ls

// main.js

/*
    引入-----本地存储插件
 */
import Storage from 'vue-ls';
const storageOptions = {
    namespace: '', // key 键的前缀
    name: 'ls', // 变量名称,使用方式:Vue.变量名称 或 this.$变量名称
    storage: 'local', // 存储名称: local, session, memory
};
Vue.use(Storage, storageOptions);
使用方法
// name:要获取的 key
// def:默认为 null。如果 key 不存在,则返回 def
this.$ls.get(name, def)

// 设置的 key 名
// 设置的 key 的 value 值
// 设置过期时间,单位毫秒
this.$ls.set(name, value, expire)

// 删除 key,成功返回 true,否则返回 false
this.$ls.remove(name)

// 清空所有 key
this.$ls.clear()

// 设置侦听器,监听 key,若发生变化时,就会触发回调函数 callback
this.$ls.on(name, callback)
callback 三个参数:
newValue: in storage 的当前值name,从持久化的 JSON 中解析
oldValue: in storage 的旧值name,从持久化的 JSON 中解析
url: 修改来源标签的 url

// 删除设置的侦听器
this.$ls.off(name, callback)

还有一个插件 vue-web-storage [https://github.com/ankurk91/vue-web-storage]

相关文章

  • vue-ls

    https://blog.csdn.net/CEZLZ/article/details/108147697[htt...

  • Vue | Vue-ls插件

    Vue插件,用于从Vue上下文中使用本地Storage,会话Storage和内存Storage 一个vue封装的本...

  • Vue | Vue-ls插件

    Vue插件,用于从Vue上下文中使用本地Storage,会话Storage和内存Storage 一个vue封装的本...

  • Vue的Vue-ls使用

    Vue插件,用于从Vue上下文中使用本地Storage,会话Storage和内存Storage 一个vue封装的本...

  • Vue的Vue-ls 封装的本地存储的方法

    Vue插件,用于从Vue上下文中使用本地Storage,会话Storage和内存Storage 一个vue封装的本...

网友评论

      本文标题:vue-ls

      本文链接:https://www.haomeiwen.com/subject/ohcfprtx.html