Im sure this has been asked before but i cant for the life of me figure out whats going on
this code in the page
fetch ({ store }) {
const response = await axios.get(dataUrl);
console.log(response.data)
store.commit("SET_SECTIONS", response.data);
}
and yet somehow this doesn't work
fetch ({store}) {
store.dispatch('fetchSections')
}
where in the store the action is doing the same thing
async fetchSections({ commit, getters }) {
const response = await axios.get(dataUrl);
console.log(response.data)
commit("SET_SECTIONS", response.data);
}
the console log is the same for both, but for some reason the one where the fetc calls the action isnt populating the store?
Any ideas?
Hi @keithmancuso, have you tried to use return in the second option?
fetch ({store}) {
return store.dispatch('fetchSections')
}
Ahh interesting that fixed it, thanks for the quick response.
Although I'm not sure i understand why?
It's because fetch() can be or return a Promise :)
right! thank you!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hi @keithmancuso, have you tried to use
returnin the second option?