(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的基本原理及源码实现 回到顶部 一. 理解 ...
随机推荐
- day03_流程控制语句
day03_流程控制语句 建议: 凡是次数确定的场景多用for循环,否则用while循环. 三元运算符 由?:符号表示的,具体的含义其实就和if-else结构的含义差不多,这种运算符会将某个条 ...
- SpringCloud与微服务Ⅳ --- Rest微服务构建案例工程模块
一.父工程搭建 父工程pom: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=& ...
- 踩坑:windows系统下,nodejs版本管理器无法使用n来管理
错误 :在windows系统下,需要npm 一个n来管理nodejs的版本,但是使用npm install -g n命令之后报错 原因 : n 不支持 windows系统 只支持mac系统.
- Topics类型配置
配置项 备注 segment.bytes 分段文件大小,最大2GB segment.ms 强制新建段文件间隔阀值时间 segment.jitter.ms 段文件抖动时间 segment.index.b ...
- 通过指针突破C++类的访问权限
看如下代码 #include "pch.h" #include <iostream> using namespace std; class A { public: A( ...
- C#系列之圣诞树代码(五)
马上就到圣诞节啦,这里我写啦一个最简单的圣诞树代码 Console.WriteLine("请输入您需要的圣诞树的大小<数字>"); int n = int.Parse( ...
- JDK的下载及安装教程图解(超详细哦~)
一.本人电脑系统介绍及JDK下载途径 1.先说明一下我的电脑为win10系统,64位操作系统~ 2.我选择下载的JDK版本为1.8版本.给大家来两个下载渠道,方便大家的下载~ JDK官网:https: ...
- jsp简单实现交互
test.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&quo ...
- 通过欧拉计划学Rust编程(第54题)
由于研究Libra等数字货币编程技术的需要,学习了一段时间的Rust编程,一不小心刷题上瘾. 刷完欧拉计划中的63道基础题,能学会Rust编程吗? "欧拉计划"的网址: https ...
- 20194653 面向对象基础3——static、this、包总结
题目1:编写一个类Computer,类中含有一个求n的阶乘的方法.将该类打包,并在另一包中的Java文件App.java中引入包,在主类中定义Computer类的对象,调用求n的阶乘的方法(n值由参数 ...