pinia的用法
安装:
yarn add pinia-plugin-persistedstate or npm i pinia-plugin-persistedstate
使用插件在main.js中注册:
import { createApp } from "vue"; import App from "./App.vue"; import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' const pinia = createPinia(); pinia.use(piniaPluginPersistedstate); createApp(App).use(pinia);
模块开启持久化
const HomeStore = defineStore("home",{ // 开启数据持久化 persist: true // ...省略 });