[英]vuex unknown mutation type in registered module
i just wanna create dynamic registered module in vuex, but it seems doesnt work. 我只是想在vuex中创建动态注册模块,但它似乎不起作用。 this is my store file 这是我的商店文件
import Vuex from 'vuex'
import descriptionModule from './module/descriptionModule';
const {state: stateModule, getters, mutations} = descriptionModule;
const createStore = () => {
return new Vuex.Store({
state: {
descriptions: [],
},
mutations: {
addDescriptions(state, payload){
state.descriptions.push(state.descriptions.length + 1);
createStore().registerModule(`descriptionModule${payload}`, {
state: stateModule,
getters,
mutations,
namespaced: true // making our module reusable
});
}
}
})
};
export default createStore
and this is my custom module that i will registered 这是我将注册的自定义模块
const state = () => {
return {description: ''}
};
const getters = {
description: (state) => state.description
};
const mutations = {
updateDescription(state, payloads){
state.description = payloads;
}
};
export default {
state,getters,mutations
}
and then this is my custom methods that will call addDescriptions mutation and commit updateDescription from registeredModule 然后这是我的自定义方法,它将调用addDescriptions变异并从registeredModule提交updateDescription
beforeMount(){
console.log("hahahaha");
this.$store.commit('addDescriptions', this.id);
},
... more code ....
methods: {
onType(editor, content){
console.log(this.$store.state.a);
console.log(this.$store.state);
console.log(this.$store);
this.$store.commit(`descriptionModule${this.id}/updateDescription`, content, {root: true})
}
}
every onType
called, i get an error unknown mutation type: descriptionModuleeditor1/updateDescription
in browser. 每个onType
调用,我得到一个错误unknown mutation type: descriptionModuleeditor1/updateDescription
onType
unknown mutation type: descriptionModuleeditor1/updateDescription
在浏览器中。
currently iam following this solution link , but it doesnt work for me :( 目前iam遵循此解决方案链接 ,但它不适合我:(
can anyone solve this,,, sorry for bad english 任何人都可以解决这个问题,抱歉英语不好
invoke $store.registerModule()
via component/pages on beforeMount()
: 通过$store.registerModule()
上的组件/页面调用$store.registerModule()
beforeMount()
:
beforeMount(){
this.$store.registerModule(`descriptionModule${this.id}`, {
state: stateModule,
getters,
mutations,
namespaced: true // making our module reusable
});
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.