3.解决页面刷新vuex值消失
3.1安装vuex-persistedstate
npm install vuex-persistedstate
3.2在store目录下index引入
import createPersistedState from 'vuex-persistedstate'
3.3配置vuex-persistedstate
将需要持久化的模块放到PERSIST_PATHS 中
不需要持久化的不要放(重中之重)
// 创建PERSIST_PATHS变量 存储要持久化的模块
const PERSIST_PATHS = ['user']
const store = new Vuex.Store({
state: {},
modules: {
app,
settings,
user,
permission,
tagsView
},
getters,
// 新增规则保存vuex的值
plugins: [createPersistedState({
storage: window.sessionStorage,
// 在此使用
paths: PERSIST_PATHS
})]
})