1.npm install --save vuex-persistedstate
2.
vuecli2
在store入口index.js文件中引入并进行对应配置
import createPersistedState from “vuex-persistedstate”;
export default new Vuex.Store({
state,
getters,
actions,
mutations,
plugins: [createPersistedState({
storage:window.sessionStorage
})]
});
vuecli3
在store入口index.js文件中引入并进行对应配置
import createPersistedState from “vuex-persistedstate”;
const vuexLocal=VuexPersistence({
storage:window.localStorage,
key:‘localData’
})
export default new Vuex.Store({
state,
getters,
actions,
mutations,
plugins:[vuexLocal]
});