1.安装 vuex-persistedstate
npm install --save vuex-persistedstate
2.使用
/store/index.js下
const store = new Vuex.Store({
modules: {
userOption,
},
plugins: [
// 解决vuex刷新失效问题
createPersistedState(
{
// 存储方式
storage: window.sessionStorage,
// 方法一:模块.数据
paths: ['userOption.user'],
// 方法二
// reducer(state) {
// // 此时,当state值发生改变的时候,就会调用此函数,当前state对象
// return {
// 'userOption.user': state.userOption.user
// }
// }
}
)
]
})