下载安装
pnpm install pinia-plugin-persistedstate
import { createPinia } from "pinia";
import persist from 'pinia-plugin-persistedstate'
const store = createPinia();
store.use(persist)
export default store;
添加一下代码
import { defineStore } from "pinia";
import {dataLeftList,userInfoList} from "@/api/data/dataone"
const userStore = defineStore("userStore",{
state:()=>{
return{
// 用户登录信息保存
userInfo:{
username:"",
password:"",
avatar:"",
roles:[],
},
dataLeftListPinia:dataLeftList,
userInfoListPinia :userInfoList
}
},
persist:true //代码重点在这里
})
export default userStore;