最近公司开了新的项目,所以提出了这个方案 pinia-plugin-persistedstate
安装
npm i pinia-plugin-persistedstate
使用 main.ts
import persist from 'pinia-plugin-persistedstate' const app = createApp(App) app.use(createPinia().use(persist))
配置 stores/user.ts
import type { User } from '@/types/user' import { defineStore } from 'pinia' import { ref } from 'vue' export const useUserStore = defineStore( 'cp-user', () => { const user = ref() { persist: true//持久化插件 } )