公式ガイドのストアのページで紹介されていたvuex-module-decorators。
nuxtServerInitをどこに書けばいいか迷ったので、いろいろ調べたときの備忘録。
こんな感じでstore/index.tsに追加するっぽい
import { ActionTree, Store } from "vuex"; import { ActionContext } from "vuex/types"; import { Context } from "@nuxt/types"; import { initialiseStores } from "~/utils/store-accessor"; // RootStateを追加 export const state = () => ({}); export type RootState = ReturnType<typeof state>; const initializer = (store: Store<any>) => initialiseStores(store); export const plugins = [initializer]; // Rootのactionsを追加 export const actions: ActionTree<any, any> = { nuxtServerInit: async ( context: ActionContext<RootState, RootState>, server: Context ) => { // nuxtServerInitの処理 } }; export * from "~/utils/store-accessor";
ほかの導入する部分は、以下の記事を参照。
以上!!