Reputation: 354
The application is build with Nuxt.js. I am trying to initiate a variable on vuex module which is used to call axios on each actions.
store/program.js
let program_url = 'programs/';
export const actions = {
async programList({commit}) {
await this.$axios.$get(program_url).then((response) => {
commit("ALL_PROGRAMS", response);
});
},
The problem I am facing is that this variable depends on a state variable in another vuex module. What I am trying to build here is on store/program.js I want to initiate a variable called program = <dynamic_id_from_another_vuex_module>/program
The other store file is store/university.js
export const state = () => ({
settings: [],
id: null
});
export const getters = {
getId(state) {
return state.id;
}
};
So How do I do something like below inside my store/program.js ?
let program = store.getters['university/getId'] + 'program';
Upvotes: 0
Views: 1771
Reputation: 1964
You need to use rootState
in your getters like following...
getId(state, getters, rootState) {
return rootState.university.id // Here I assume university is the another module
}
That's it :)
Upvotes: 2