Gathering detailed insights and metrics for pinia-plugin-unistorage
Gathering detailed insights and metrics for pinia-plugin-unistorage
Gathering detailed insights and metrics for pinia-plugin-unistorage
Gathering detailed insights and metrics for pinia-plugin-unistorage
npm install pinia-plugin-unistorage
Typescript
Module System
Node Version
NPM Version
71.3
Supply Chain
98.3
Quality
79.6
Maintenance
100
Vulnerability
100
License
JavaScript (48.11%)
TypeScript (20.63%)
SCSS (20.09%)
HTML (6.42%)
Vue (4.74%)
Total Downloads
10,113
Last Day
5
Last Week
147
Last Month
557
Last Year
4,898
MIT License
21 Stars
56 Commits
2 Forks
1 Watchers
1 Branches
2 Contributors
Updated on Jun 07, 2025
Minified
Minified + Gzipped
Latest Version
0.1.2
Package Id
pinia-plugin-unistorage@0.1.2
Unpacked Size
14.31 kB
Size
5.05 kB
File Count
5
NPM Version
10.5.0
Node Version
20.12.2
Published on
Jul 17, 2024
Cumulative downloads
Total Downloads
Last Day
-16.7%
5
Compared to previous day
Last Week
50%
147
Compared to previous week
Last Month
-17.5%
557
Compared to previous month
Last Year
48.1%
4,898
Compared to previous year
4
uniapp 下 pinia 的本地数据缓存插件
该插件是
pinia-plugin-persistedstate
的 uniapp
版本,如果你需要在纯 vue
或者 nuxt
项目中使用 pinia
的本地数据缓存,请使用
pinia-plugin-persistedstate。
为了实现多端的更简单的全局本地数据缓存
欢迎关注 帝莎编程
cli
创建的 uniapp
项目1npm i pinia-plugin-unistorage -D
1// main.js 2import { createSSRApp } from "vue"; 3import * as Pinia from "pinia"; 4import { createUnistorage } from "pinia-plugin-unistorage"; 5 6export function createApp() { 7 const app = createSSRApp(App); 8 9 const store = Pinia.createPinia(); 10 11 // 关键代码 👇 12 store.use(createUnistorage()); 13 14 app.use(store); 15 16 return { 17 app, 18 Pinia, // 此处必须将 Pinia 返回 19 }; 20}
hbuilderx
创建的 uniapp
项目👉 直接插件市场安装 后引入注册
1// main.js 2import { createSSRApp } from "vue"; 3import * as Pinia from "pinia"; 4import { createUnistorage } from "./uni_modules/pinia-plugin-unistorage"; 5 6export function createApp() { 7 const app = createSSRApp(App); 8 9 const store = Pinia.createPinia(); 10 11 // 关键代码 👇 12 store.use(createUnistorage()); 13 14 app.use(store); 15 16 return { 17 app, 18 Pinia, // 此处必须将 Pinia 返回 19 }; 20}
1import { defineStore } from "pinia"; 2 3export const useStore = defineStore("main", { 4 state() { 5 return { 6 someState: "hello pinia", 7 }; 8 }, 9 unistorage: true, // 开启后对 state 的数据读写都将持久化 10});
或者 setup
语法也是支持的
1import { defineStore } from "pinia"; 2 3export const useStore = defineStore( 4 "main", 5 () => { 6 const someState = ref("hello pinia"); 7 return { someState }; 8 }, 9 { 10 unistorage: true, // 开启后对 state 的数据读写都将持久化 11 }, 12);
1import { defineStore } from "pinia"; 2 3export const useStore = defineStore("main", { 4 state() { 5 return { 6 someState: "hello pinia", 7 }; 8 }, 9 unistorage: { 10 // 初始化恢复前触发 11 beforeRestore(ctx) {}, 12 // 初始化恢复后触发 13 afterRestore(ctx) {}, 14 }, 15});
大多数情况下你并不需要了解该选项
1import { defineStore } from "pinia"; 2 3export const useStore = defineStore("main", { 4 state() { 5 return { 6 someState: "hello pinia", 7 }; 8 }, 9 unistorage: { 10 serializer: { 11 // 序列化,默认为 JSON.stringify 12 serialize(v) { 13 return JSON.stringify(v); 14 }, 15 // 反序列化,默认为 JSON.parse 16 deserialize(v) { 17 return JSON.parse(v); 18 }, 19 }, 20 }, 21});
1import { defineStore } from "pinia"; 2 3export const useStore = defineStore("main", { 4 state() { 5 return { 6 foo: "foo", 7 nested: { 8 data: "nested pinia", 9 }, 10 someState: "hello pinia", 11 }; 12 }, 13 unistorage: { 14 key: "foo", // 缓存的键,默认为该 store 的 id,这里是 main, 15 paths: ["foo", "nested.data"], // 需要缓存的路径,这里设置 foo 和 nested 下的 data 会被缓存 16 }, 17});
Made with markthree
Published under MIT License.
No vulnerabilities found.
No security vulnerabilities found.