Open felixoi opened 4 years ago
i am also facing this problem
Avoiding the duplicating, I'll post my instance here.
I am sorry for the question in issues. Before open this issue, I asked same question in StackOverflow and even did the contest. The only one answer does not contain the working solution.
According this answer on Stack overflow, 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);
}
}
});
The David Bernal's solution works, but with warning:
WARN Classic mode for store/ is deprecated and will be removed in Nuxt 3.
import Vuex, { Store } from "vuex";
interface RootState {}
export const store = new Vuex.Store<RootState>({
actions: {
nuxtServerInit: () => {
console.log("Hello nuxtServerInit");
}
}
});
const createStore = (): Store<RootState> => {
return store;
};
export default createStore;
Hey, I'm using nuxt-property-decorator which just exports some stuff of this module. So I'm reporting it here, because i think it's not a question for the nuxt-property-decorator module. I've created this module (store/usermodule.ts):
And i want to call the init action on nuxtServerInit so i created this store/index.ts
store-accessor:
When doing so I'm running into the following error:
Without the dispatch to the usermodule everything is working fine. Whats the correct way of doing this?