admin管理员组文章数量:1429064
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);
}
本文标签: javascriptNuxtjs window is not definedStack Overflow
版权声明:本文标题:javascript - Nuxt.js: window is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745439967a2658400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论