// nuxt.config.jsmodule.exports={modules:[['nuxt-vuex-localstorage',{localStorage:['foo','bar'],// If not entered, “localStorage” is the default valuesessionStorage:['sfoo','sbar']// If not entered, “sessionStorage” is the default value}]]}// store/index.jsexportconststate=()=>...
// nuxt.config.jsmodule.exports={modules:[['nuxt-vuex-localstorage',{mode:'manual'}]]} At first, insert status value (whether true or false) in store file of web storage. // store/localStorage.js or store/sessionStorage.jsexportconststate=()=>({...status:false}) ...
//在页面刷新时将vuex里的信息保存到localStorage里 window.addEventListener("beforeunload",()=>{ localStorage.setItem("storeState",JSON.stringify(this.$store.state)) }) } 1 2 3 4 5 6 7 Cookie,nuxtServerInit nuxtServerInit 这个是Nuxt提供的方法,简单说,就是在页面刷新的时候,在到达页面之前。给你...
// nuxt.config.js module.exports = { modules: [ ['nuxt-vuex-localstorage', { mode: 'api', api: 'https://ipinfo.io', // If not entered, “https://ipinfo.io” is the default value keyName: 'ip', // If not entered, “ip” is the default value saltName: 'region' // If ...
弄了几个小时,才算是解决nuxt刷新vuex失效的问题。 vuex-persist 方法在线上使用的时候会报错。所以建议直接使用localStorage,或Cookile方法 下面具体演示,都以state中的token为例 使用vuex-persist线上报错的原因 线上发布使用的是node,但是在node里面没有window这个对象。初始化vuex-persist的时候使用到了window ...