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