Я пытаюсь программно вызвать мутацию из файла js. Я просто не могу получить правильный синтаксис, и я продолжаю получать ReferenceErrors, например, «бар не определен».
У меня есть следующие настройки:
//substore.js
export default {
namespaced: true,
state: {
foo:[]
},
mutations:{
bar(state) {
//...
}
},
};
//store.js
import substore from '/pathTo/substore.js';
Vue.use(Vuex);
export default new Vuex.Store({
modules :{
substore
}
});
//someFile.js
import store from 'pathTo/store.js';
someMethod(){
console.dir(store);
// Shows all the store data. The relevant data is:
// _mutations is an Object within store
// substore/bar is an Array[1] within the Object
// 0: wrappedMutationHandler() length:1 is inside the Array
store._mutations.substore.bar(); // Can't get this to work
store._mutations.substore/bar(); // Can't get this to work either
store._mutations['substore/bar']; // Can't get this to work either
}
Для чего бы это ни стоило, оно работает как положено, если я использую компонент.
import {mapMutations} from 'vuex';
export default {
methods: {
...mapMutations({bar:'substore/bar'}),
baz(){
this.bar();
}
},
};