(vue操作storage)Vue plugin for work with local storage,session storage and memo
vue-ls
https://www.npmjs.com/package/vue-ls
NPM
npm install vue-ls --save
Yarn
yarn add vue-ls
Usage
Vue storage API.
import Storage from 'vue-ls';
options = {
namespace: 'vuejs__', // key prefix
name: 'ls', // name variable Vue.[ls] or this.[$ls],
storage: 'local', // storage name session, local, memory
};
Vue.use(Storage, options);
//or
//Vue.use(Storage);
new Vue({
el: '#app',
mounted: function() {
Vue.ls.set('foo', 'boo');
//Set expire for item
Vue.ls.set('foo', 'boo', 60 * 60 * 1000); //expiry 1 hour
Vue.ls.get('foo');
Vue.ls.get('boo', 10); //if not set boo returned default 10
let callback = (val, oldVal, uri) => {
console.log('localStorage change', val);
}
Vue.ls.on('foo', callback) //watch change foo key and triggered callback
Vue.ls.off('foo', callback) //unwatch
Vue.ls.remove('foo');
}
});
Global
Vue.ls
Context
this.$ls
API
Vue.ls.get(name, def)
Returns value under name in storage. Internally parses the value from JSON before returning it.
def: default null, returned if not set name.
Vue.ls.set(name, value, expire)
Persists value under name in storage. Internally converts the value to JSON.
expire: default null, life time in milliseconds name
Vue.ls.remove(name)
Removes name from storage. Returns true if the property was successfully deleted, and false otherwise.
Vue.ls.clear()
Clears storage.
Vue.ls.on(name, callback)
Listen for changes persisted against name on other tabs. Triggers callback when a change occurs, passing the following arguments.
newValue: the current value for name in storage, parsed from the persisted JSON
oldValue: the old value for name in storage, parsed from the persisted JSON
url: the url for the tab where the modification came from
Vue.ls.off(name, callback)
Removes a listener previously attached with Vue.ls.on(name, callback).
(vue操作storage)Vue plugin for work with local storage,session storage and memo的更多相关文章
- 关于local storage 和 session storage以及cookie 区别简析
session storage 和local storage 都是存储在客户端的浏览器内: 一:关于COOKIE 的缺陷 * Cookie的问题 * 数据存储都是以明文(未加密)方式进行存储 * 安全 ...
- vue操作select获取option值
如何实时的获取你选中的值 只用@change件事 @change="changeProduct($event)" 动态传递参数 vue操作select获取option的ID值 如果 ...
- vue操作数组时遇到的坑
用vue操作数组时,一般就那几个方法,而且是可以渲染的,但是有时候列表是渲染不了的先说下操作数组的几个方法吧 1 push ( ) 这个方法是在数组的最后面添加元素 用法: 括号里写需要加入的元素 ...
- 黑马eesy_15 Vue:04.Vue案例(ssm环境搭建)
黑马eesy_15 Vue:02.常用语法 黑马eesy_15 Vue:03.生命周期 黑马eesy_15 Vue:04.Vue案例(ssm环境搭建) 黑马eesy_15 Vue:04.综合案例(前端 ...
- Vue.js起手式+Vue小作品实战
本文是小羊根据Vue.js文档进行解读的第一篇文章,主要内容涵盖Vue.js的基础部分的知识的,文章顺序基本按照官方文档的顺序,每个知识点现附上代码,然后根据代码给予个人的一些理解,最后还放上在线编辑 ...
- Vue.js之Vue计算属性、侦听器、样式绑定
前言 上一篇介绍了Vue的基本概念,这一篇介绍一下Vue的基本使用. 一.搭建一个Vue程序 1.1 搭建Vue环境 搭建Vue的开发环境总共有三种方法: 引入CDN <script src=& ...
- Vue之初识Vue
前言 如果你之前已经习惯了用jQuery操作DOM,学习Vue.js时请先抛开手动操作DOM的思维, 因为Vue.js是数据驱动的,你无需手动操作DOM.它通过一些特殊的HTML语法,将DOM和 数据 ...
- Vue系列---理解Vue.nextTick使用及源码分析(五)
_ 阅读目录 一. 什么是Vue.nextTick()? 二. Vue.nextTick()方法的应用场景有哪些? 2.1 更改数据后,进行节点DOM操作. 2.2 在created生命周期中进行DO ...
- vue系列---理解Vue中的computed,watch,methods的区别及源码实现(六)
_ 阅读目录 一. 理解Vue中的computed用法 二:computed 和 methods的区别? 三:Vue中的watch的用法 四:computed的基本原理及源码实现 回到顶部 一. 理解 ...
随机推荐
- JavaScript中this的使用及含义(总结)
this 1.谁调用,指向谁 2.事件监听函数中,this指向,绑定监听函数的那一个元素节点 即,谁绑,指向谁 3.当一个函数没有被其他对象调用时,(普通调用),this指向全局对象(严格模式下面是u ...
- BBOTSTRAP
Bootstrap 第一步:下载 第二步: 解压缩 第三步:引入(head内部 link引入) Bootstrap 全局样式 移动设备优先:<meta name="viewport& ...
- ios--->特定构造方法NS_DESIGNATED_INITIALIZER
特定构造方法 1> 后面带有NS_DESIGNATED_INITIALIZER的方法,就是特定构造方法 2> 子类如果重写了父类的[特定构造方法],那么必须用super调用父类的[特定构造 ...
- Docker三剑客之compose
简介 Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排.从功能上看,跟 OpenStack 中的 Heat 十分类似.其代码目前在 https://g ...
- springboot中使用Caffeine本地缓存
Caffeine是使用Java8对Guava缓存的重写版本性能有很大提升 一 依赖 <dependency> <groupId>org.springframework.boot ...
- 8、OSPF
OSPF ---最短路径优先 用于在单一自治系统(Autonomous System-AS)内决策路由 自制系统(AS)AS: 执行统一路由策略的一组网络设备的组合可适应大规模的网络: · 路由 ...
- Lighthouse
北大程郁缀教授: 一,"日月之行,若出其中,星汉灿烂,若出其里."要找机会去感受大海,男人要有大海一样的胸怀,大气者方能成大器. 二,"亦余心之所善兮,虽九死其而未悔.& ...
- windows 使用ssh连接docker容器
在Windows上搭建docker服务器需要在Windows模拟一个Linux平台,然后在Linux平台上搭建的docker服务器,所以在使用ssh工具连接docker容器的时候,使用的ip地址不是d ...
- HDU_3415_单调队列
http://acm.hdu.edu.cn/showproblem.php?pid=3415 初探单调队列,需要注意的是每次i维护的是i-1. #include<iostream> #in ...
- Educational Codeforces Round 57
2018.12.28 22:30 看着CF升高的曲线,摸了摸自己的头发,我以为我变强了,直到这一场Edu搞醒了我.. 从即将进入2018年末开始,开启自闭场集合,以纪念(dian)那些丢掉的头发 留 ...