I define a store with two modules, and I'm trying to access one module action, I tried to do
this.$store.dispatch('load');
But I get:
[vuex] unknown action type: load
I tried another options, thing that I found in google , but nothing worked, what is the right way to access module actions?
This is my code:
Vuex definition:
let session = require('./store/session.js');
let options = require('./store/options.js');
const store = new Vuex.Store({
modules: {
session: session,
options: options,
},
});
options.js
export default {
state: {
data: null,
},
mutations: {
setOptions (state, payload) {
console.log(payload);
}
},
actions: {
load( { commit }) {
$.getJSON('options')
.then(function (data) {
commit('setOptions', data);
});
}
},
getters: {
}
}
and my app component:
export default {
beforeCreate() {
this.$store.dispatch('load');
}
}
my vue build:
new Vue({
el: "#app",
router,
store,
render: h => h(App)
});
console.log(this.$store)
in yourbeforeCreate() {}
hook? There should be an_actions
object that shows all of the available actions. – visevo