Answer the question
In order to leave comments, you need to log in
getter not called after mutation?
After going to the page and pressing the button, the getter called on the page through the computed property does not work.
Although after reloading the page everything works. What could be the problem ?
I put the console after the mutation, the data writes new ones, since the language is switched.
export const state = () => {
items: []
};
export const getters = {
getMenuItems: state => state.items
};
export const mutations = {
setMenu(state, items) {
state.items = items;
}
};
export const actions = {
async getMenu({rootState, commit}) {
const { auth, lang } = rootState;
const {items} = await this.$axios.$get(`/api/${ lang.locale }/menu`, {
headers: {
'Authorization': `bearer ${auth.token}`,
'Accept-Language': `${lang.locale}`
},
});
if (items) {
// set items
commit('setMenu', items);
}
}
};
```
```
computed: {
...mapGetters({menuItems: 'menu/getMenuItems'}),
},
watch: {
menuItems: function (newValue, oldValue) {
console.log(newValue); // это сообщение не выводится в описанном случае
}
}
Answer the question
In order to leave comments, you need to log in
Found my mistake
export const state = () => {
items: []
};
export const state = () => ({
items: []
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question