I am using Nuxt.js. The following problem occurred with setting up vuex-persist. Could someone help me?
store/index.js
store/LangModule.js
I am using Nuxt.js. The following problem occurred with setting up vuex-persist. Could someone help me?
store/index.js
store/LangModule.js
Share Improve this question edited Sep 29, 2020 at 19:21 10 Rep 2,2707 gold badges21 silver badges33 bronze badges asked Sep 29, 2020 at 16:35 Varga MárkVarga Márk 231 silver badge5 bronze badges 1-
you cant call
window
on store file. you have to import it as plugin and call it on cliend side not server side, please read the documentation. already mention there npmjs./package/vuex-persist – Jazuly Commented Sep 29, 2020 at 23:56
1 Answer
Reset to default 3It's important to know Nuxt works on both server and client sides, so you cannot use window
in all places since it only exists on client side.
You can declare this plugin SSR-free to avoid running it on server side.
Following the documentation:
nuxt.config.js
export default {
plugins: [
{ src: '~/plugins/vuex-persist', ssr: false }
]
}
~/plugins/vuex-persist.js
import VuexPersistence from 'vuex-persist'
export default ({ store }) => {
new VuexPersistence({
/* your options */
}).plugin(store);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745439967a4627784.html
评论列表(0条)