Currently this is still an open issue for vuex
, as you can see here: Access module namespace from within module #1244. There are a lot of workarounds for this request, but I want to show you an easy one according to your provided code.
This:
this.$store.commit("a/setName", name);
this.$store.commit("b/setName", name);
... could be this:
this.$store.dispatch('a/setName', {namespace: "a", data: name})
this.$store.dispatch('b/setName', {namespace: "b", data: name})
Yes, that means that you need to manually apply the name of that namespace you are calling, but in your example you already did it. In your action it could be something like this:
setName({commit}, object) {
console.log(object.namespace); // submitted namespace
commit('SET_THIS_NAME', object.data); // your data
}
Please note, this is only a workaround, as there still isn´t an official possibility to access the namespace inside the vuex
module. And so this isn´t an official way, but one way of workaround.