pinia持久化

1、安装插件: 

npm i pinia-plugin-persistedstate

2、在store/index.js里

// store/index.js
import {createPinia} from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

export default pinia

3、

export const useUserInfor = defineStore(
  "userinfor",
  {
    state: () => {
      return {
        imageUrl: "",
        name: "",
        sex: "",
        department: "",
        identity: "",
        account: "",
        email: "",
      };
    },
  },{
persist:true
}
);
posted @ 2023-11-12 02:53  Baipei  阅读(256)  评论(0)    收藏  举报