vuex not loading module decorated with vuex-module-decorators

Deadly 提交于 2019-12-04 18:49:35

I found the answer to be the example vue admin app was not structured quite correctly.

Instead to export the class from the module:

@Module({ name: 'authentication' })
export default class Authentication extends VuexModule implements IAuthenticationState {

Then inject the class as a module into the index and export the module via the decorator but also inject the store into the said decorator:

import Vue from 'vue';
import Vuex from 'vuex';
import Authentication from './modules/authentication';
import VuexPersistence from 'vuex-persist';
import { getModule } from 'vuex-module-decorators';

Vue.use(Vuex);

const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
});

const store = new Vuex.Store({
  modules: {
    authentication: Authentication,
  },
  plugins: [vuexLocal.plugin],
});

export default store;
export const AuthenticationModule = getModule(Authentication, store);

The result is it all works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!