更新记录

3.0.0(2022-04-22)

代码重构,数据按需写入内容,移除vue2的支持

2.1.0(2022-03-17)

添加不需要判断版本信息的获取方式

2.0.4(2022-03-17)

fix: 数据初始化绑定异常

查看更多

平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.3.10 app-vue app-nvue
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari

数据均为双向绑定与vue视图一直无需手动刷新 for vue3

install

NPM

npm uni-local-storage --save

YARN

yarn add uni-local-storage

Usage

uni storage API

import { createStorage } from "@/uni_modules/suixin-uni-local-storage"; // or import { createStorage } from "uni-local-storage";

// 实例化存储
const config = {
  namespace: "__ls__", // 当前存储key前缀 推荐动态读取manifest.json文件中AppID(appid)
  name: "ls" // 可选 自定义全局变量名称
}
// name 默认 ls;
const storage = createStorage(config);
// #ifdef VUE3
const app = createSSRApp(App);
app.use(storage);
// #endif

Context

  import { useStore } from "uni-local-storage";
  const store = useStore("foo");
  store.setEffectiveTime(10) // 设置数据有效时间 s
  console.log(store.state) // 数据内容;
  store.state = "any" // 设置数据内容

API

const store = useStore(name)

返回key为name的本地存储数据store

store.setEffectiveTime(time);

设置当前store的有效时间(单位秒)。

  • 不设置表示永久生效,每次更新数据会重新倒计时
store.removeEffectiveTime();

移除store的有效时间,永久有效

store.state = undefined;

删除当前store本地存储数据

store.state = "any";

设置当前store数据

仅支持uni支持的数据类型

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问