代码如下:Vue.use(Vuex)constlocalLoginData=global.localStorage;conststore=newVuex.Store({state:{logindata:JSON.parse(localStorage.getItem('logindata')),//初始化vuex,刷新时获取localstorageform1:{}//登录信息},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
提交
取消