I'm trying to set state vuex on my Nuxt.js App, but it don't work correctly. So here i'm set my state with fetch method:
fetch({app, store, route}) {
app.$axios.$get(`apps/${route.params.id}`)
.then(res => {
store.dispatch('setApp', {
...res,
id: route.params.id
})
console.log(app.store.state.app);
})
}
Here everything works correcty when i'm logging app.store, data is there, but when i'm trying to log it in:
created() {
console.log(this.$store);
},
mounted() {
console.log(this.$store);
}
Here's my store code:
const store = () => new Vuex.Store({
state: {
app: ''
},
mutations: {
'SET_APP' (state, payload) {
state.app = payload
}
},
actions: {
setApp (ctx, payload) {
ctx.commit('SET_APP', payload)
}
},
getters: {
}
})
i't don't work my state is empty so data is not render on my template ( I hope that somebody gotta help me !
P.S: Also when it's logging on client-side everything works fine, but in SSR not (
setAppaction to your question ? And also, I don't think that you are logging in the right place, since thecreatedandmountedlifecycle hooks will be executed before yourfetchwill be done. - Thomas Ferroappstate ? - Thomas Ferro