Nuxt延迟加载Vuex模块

时间:2020-09-07 10:57:55

标签: vuex nuxt.js vuex-module-decorators

我正在尝试在nuxtjs中完成我的状态的延迟加载。 我正在使用vuex-module-decorators软件包。

我将状态保留在“ store /”文件夹之外,因此nuxt不会自动注册它们。 加载页面后,我会注册状态并立即加载它:

created(){
    this.$store.registerModule('myModule', MyModule);
    this.myState = getModule(MyModule, this.$store);
}

稍后在按钮上单击“我打电话”: this.mystate.doStuff();,但出现错误。

Uncaught (in promise) Error: ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access this.someMutation() or this.someGetter inside an @Action? 
That works only in dynamic modules. 
If not dynamic use this.context.commit("mutationName", payload) and this.context.getters["getterName"]
Error: Could not perform action doStuff
...
Error: ERR_STORE_NOT_PROVIDED: To use getModule(), either the module
            should be decorated with store in decorator, i.e. @Module({store: store}) or
            store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)

我希望使用vuex-module-decorators的“动态”选项,但是我无法在Vue组件之外获得对存储对象的引用。

Vuex模块的外观如下:

@Module({
  name: 'myModule',
  stateFactory: true,
  namespaced: true,
})
export default class MyModule extends VuexModule {

  @Action
  doStuff(){
    console.log('DoStuff');
  }
}

按照here所述删除name属性也无法正常工作。

0 个答案:

没有答案