Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

vuex-module-decorators 动态注册 多个命名空间的模块 如何引用其他模块的方法

// common 模块
@Module({ name: 'common', dynamic: true, namespaced: true, store, stateFactory: true })
export default class Common extends VuexModule {
     @Action({ commit: 'other/updateName' }) // other 是其他模块下面的Mutations
     useOtherMutations(data: UserInfoSchame):UserInfoSchame {
         console.log(this);
         return data;
    }
 
     @Action({ commit: 'rootFun' }) // rootFun是全局的 Mutation的方法
     useRootMutations(data: UserInfoSchame):UserInfoSchame {
         console.log(this);
         return data;
     }
}

// other模块
@Module({ name: 'other', dynamic: true, namespaced: true, store, stateFactory: true })
export default class Other extends VuexModule {
     @Mutation
     updateName(data: string): void{
        this.name = 'hello world';
     }
}

// 全局 mutations
export default {
 rootFun(state:State, data?: string): void{
    state.name = 'hello world';
 }
}

上面的commit写法如果按照传统的vuex写法 是没有问题的 但是vuex-module-decorators 写法就会有问题 如果把namespaced:false 就没问题 为 true就会报错:如下

vuex.esm.js?2f62:787 [vuex] unknown local mutation type: other/updateName, global type: common/other/updateName


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
600 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...