M
M
Mainstand2019-04-11 17:38:02
JavaScript
Mainstand, 2019-04-11 17:38:02

Why doesn't nuxtServerInit work in vuex modules?

nuxtServerInit doesn't fire when used in vuex modules.

async nuxtServerInit({commit}){
        await this.$axios
            .get(apiURL + '/section')
            .then((result) => {
                commit('SET_SECTION_LIST', result.data)
            })
            .catch((error) => {
                commit('SET_ERRORS', error)
            })
    }

For example, when used in a namespace, in store/articles.js this code does not work, in store/index.js the same code works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wallydnb, 2019-04-12
@Mainstand

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.
nuxtServerInit is only called from the main module. You can call dispatch to notify another module.
async nuxtServerInit({ dispatch }) {
    await dispatch('core/load')
}

Documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question