@xingyuelongchen/vue3-storage
v0.0.11
Published
浏览器Storage使用插件, Storage! Good!
Downloads
13
Maintainers
Readme
@xingyuelongchen/vue3-storage
支持 vue3 的浏览器缓存插件
安装
下载 npm 包
npm i @xingyuelongchen/vue3-storage --save
使用方式
可使用方法名
/**
* 参数说明:
* @param {String} key 名称
* @param {Array|Object|Boolean|Number|String} value 保存的数据
* @param {Boolean} type true为sessionStorage, false为localStorage
*/
setStore(key, value, type); // 保存数据
getStore(key); // 获取指定数据
getAllStore(type); // 获取全部数据
removeStore(key); //删除指定数据
clearStore(type); //清空数据
clearAllStore(); //清空localStorage和sessionStorage全部数据
setCookie(key, value); // 设置cookie 浏览器cookie限制,使用cookie存储数据,不能过大,否则会出问题
getCookie(key); // 获取指定cookie
setsCookie(key, value); // 设置cookie
getsCookie(key); // 获取指定cookie
clearCookie(key); //清除指定cookie
Global instruction 全局注册
import store from "@xingyuelongchen/vue3-storage";
// Vue3 注册插件
App.use(store);
// or 使用配置项
App.use(store, { key: "存储前缀", domain: "", maxage: 86400, path: "/" });
// Vue2.x 注册插件
// Vue.use(store);
// 在Vue组件内使用this访问
this.$setStore("key", "value");
Local instruction 局部调用
import { setStore, …… } from "@xingyuelongchen/vue3-storage";
// 直接调用相关方法
setStore('key','value')
Run demo
npm install
npm run serve
-Local: http://localhost:8080/