javascript - Nuxt.js: window is not defined - Stack Overflow

I am using Nuxt.js. The following problem occurred with setting up vuex-persist. Could someone help me?

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
Add a ment  | 

1 Answer 1

Reset to default 3

It'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

相关推荐

  • javascript - Nuxt.js: window is not defined - Stack Overflow

    I am using Nuxt.js. The following problem occurred with setting up vuex-persist. Could someone help me?

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信