Reputation: 5131
In the Vuex Store, I define nuxtServerInit()
which doesn't initialize at all!
import Vuex from 'vuex'
import mod1 from './modules/mod1'
import mod2 from './modules/mod2'
const store = () => {
return new Vuex.Store({
actions: {
nuxtServerInit() {
setTimeout(() => console.log('Hello'), 10000)
}
},
modules: {
mod1,
mod2
}
})
}
export default store
Am I doing something wrong? Please help!
Upvotes: 1
Views: 2672
Reputation: 204
Are you sure that you are calling NuxtServerInit
from store/index.js
and you are not in a module mode?
If you are using the Modules mode of the Vuex store, only the primary module (in store/index.js) will receive this action. You'll need to chain your module actions from there.
https://nuxtjs.org/guide/vuex-store/
Upvotes: 1
Reputation: 2823
You can try like below example
actions: {
nuxtServerInit ({ commit }, { req }) {
if (req.session.user) {
commit('user', req.session.user)
}
}
}
more details here
Upvotes: 0