According this answer, below listing from the vuex-module-decorators official documentation
// @/store/index.ts
import Vuex from 'vuex'
const store = new Vuex.Store({
/*
Ideally if all your modules are dynamic
then your store is registered initially
as a completely empty object
*/
})
in the Nuxt case must be:
import Vue from "vue";
import Vuex, { Store } from "vuex";
Vue.use(Vuex);
export const store: Store<unknown> = new Vuex.Store<unknown>({});
But how to integrate the nuxtServerInit
action is above methodology?
In below listing of store/index.ts
, the nuxtServerInit
will not be called.
import Vue from "vue";
import Vuex, { Store } from "vuex";
Vue.use(Vuex);
export const store: Store<unknown> = new Vuex.Store<unknown>({
actions: {
nuxtServerInit(context: unknown): void {
console.log("Called !");
console.log(context);
}
}
});
nuxtServerInit
can be used only instore/index.js
file, this is server side action and can not be used from the client side.