1
votes

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!

2
nuxtServerInit runs on the server. Is it printing to your command line console? Are you running in spa mode? - David Weldon
No I am not running at SPA mode. I am on universal mode - Damon
Even the axios doesn't work in nuxtServerInit() - Damon

2 Answers

1
votes

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/

0
votes

You can try like below example

actions: {
  nuxtServerInit ({ commit }, { req }) {
    if (req.session.user) {
      commit('user', req.session.user)
    }
  }
}

more details here