So, I don't get how to set an array of data fetched by API in Vuex.
This is what I'm trying
/* store/modules/galleries.js */
// mutations
const mutations = {
SET_GALLERIES(state, galleries) {
state.galleries = galleries;
}
};
// actions
const actions = {
fetchAllGalleries({ commit }) {
Vue.prototype.$oauth.request('/galleries')
.then(galleries => {
console.log(galleries) // [{...}, {...}, ...]
commit('SET_GALLERIES', galleries);
});
}
}
/* myComponent.vue */
computed: {
...mapState('galleries', ['galleries'])
},
mounted() {
this.$store.dispatch('galleries/fetchAllGalleries');
}
But somehow my state.galleries always stay at his original state even though the commit is called.
What could be the error coming from?
