添加了pina状态管理缓存插件pinia-plugin-persist

This commit is contained in:
abu 2024-04-08 11:02:21 +08:00
parent 5981660efc
commit 8020b9d858
2 changed files with 13 additions and 0 deletions

View File

@ -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)

View File

@ -19,4 +19,14 @@ export const useCounterStore = defineStore('counter', {
this.count--
}
},
// 开启缓存
persist: {
enabled: true,
strategies: [
{
key: 'counter',
storage: localStorage,
},
],
},
})