From 8020b9d8583aa9d46b6ec676ce396a4c9313ad30 Mon Sep 17 00:00:00 2001 From: abu <2742828146@qq.com> Date: Mon, 8 Apr 2024 11:02:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86pina=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86=E7=BC=93=E5=AD=98=E6=8F=92=E4=BB=B6?= =?UTF-8?q?pinia-plugin-persist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 3 +++ src/store/index.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main.ts b/src/main.ts index 2f94a0a..e783ebb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,9 @@ import Vant from 'vant' import 'vant/lib/index.css'; const app = createApp(App); const pinia = createPinia() +import piniaPluginPersist from 'pinia-plugin-persist' //++++缓存 +pinia.use(piniaPluginPersist) //++++缓存 + app.use(Vant); app.use(pinia) app.use(router) diff --git a/src/store/index.ts b/src/store/index.ts index 7ee2ab2..f2ce7b9 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -19,4 +19,14 @@ export const useCounterStore = defineStore('counter', { this.count-- } }, +// 开启缓存 + persist: { + enabled: true, + strategies: [ + { + key: 'counter', + storage: localStorage, + }, + ], + }, }) \ No newline at end of file