vuex-persistedstate插件
持久化的插件,帮助我们在刷新时state数据不会被清空,自动存储,更改state也会自动存储,直接用this.$store.commit(“SET_CONFIGAREA”, val)存储,this.$store.state…获取即可
下载:npm install --save vuex-persistedstate
引入:import createPersistedState from "vuex-persistedstate";
使用:export default new Vuex.Store({
state: {
configArea: "杭州",
},
mutations: {
// 设置配置区域
SET_CONFIGAREA(state, configArea) {
state.configArea = configArea;
},
},
modules,
plugins: [
createPersistedState({
//默认是localStorage储存,修改为sessinStorage
storage: window.sessionStorage,
reducer(val) {
let element = JSON.parse(JSON.stringify(val));
//使用delete element.模块名.变量名可以指定哪些变量不被存储
delete element.dispatchflow.svgContextMap;
delete element.dispatchflow.svgZoomMap;
delete element.dispatchflow.showRadio;
return element;
},
}),
],
});