【发布时间】:2020-03-15 21:01:18
【问题描述】:
使用 vuex-module-decorators 遇到这样的问题。我想创建一些父模块,以便可以从中扩展子模块并继承其动作和吸气剂。但是 getter 不会被继承。
我是这样试过的:
我的parent-module.ts:
import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators';
export class ParentStore extends VuexModule {
public get getterForInherit(): any {
return someData
}
}
子模块:
child-one.ts:
import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators'
import {ParentModule} from './parent-module';
@Module({dynamic: true, store: Store, name: 'childOne', namespaced: true})
class FirstChildModule extends ParentModule {
public get SecondChildGetter(): number {
return 1;
}
}
export const FirstChildStore: ParentModule = getModule(FirstChildModule)
child-two.ts:
import {Action, getModule, Module, Mutation, VuexModule} from 'vuex-module-decorators'
import {ParentModule} from './parent-module';
@Module({dynamic: true, store: Store, name: 'childTwo', namespaced: true})
class SecondChildModule extends ParentModule {
public get FirstChildGetter(): number {
return 2;
}
}
export const SecondChildStore: ParentModule = getModule(SecondChildModule)
但是当我将这些模块导入组件时,getterForInherit 不可用。这种方式可以吗?
【问题讨论】: