vuex中提交mutations的时候保存到localstorage,想在刷新时从state新获取localstorage。Vue.use(Vuex)const localLoginData = global.localStorage;const store = new Vuex.Store({ state: { logindata:JSON.parse(localStorage.getItem('logindata')), // 初始化vuex,刷新时获取localstorage form1: {} //登录信息 }, getters:{ getUserInfo:(state)=>state.logindata==null?'':state.logindata, }, mutations: { updatelogindata(state, logindata) { state.logindata = logindata; localStorage.setItem('logindata',JSON.stringify(logindata));// 提交mutation成功后保存logindata到localStorage }, updatamessage(state, form1) { state.form1 = form1 } },为什么一刷新还是state还是清空了,明明已经保存成功到了localstorage里了啊,试过很多方法了,难道vuex不能实现持久化缓存么?
添加回答
举报
0/150
提交
取消