1、安装
npm i vuex-persistedstate yarn add vuex-persistedstate
2、在store.js中引入
import createPersistedState from "vuex-persistedstate"
举例:
import Vue from 'vue' import Vuex from 'vuex' import createPersistedState from "vuex-persistedstate" Vue.use(Vuex) const store = new Vuex.Store({ state:{ userInfo:{}, MetaMaskProvider : 'ethereum', NaboxProvider : 'NaboxWallet', }, actions:{ }, mutations:{ setUserInfo(state, val){ state.userInfo = val.val }, }, plugins: [createPersistedState({ key: 'userinfor', storage: window.localStorage, })] }) export default store
得到:
标签:持久,val,Vuex,state,persistedstate,import,vuex From: https://www.cnblogs.com/tlfe/p/17401355.html