我很难让我的 vuex 模块与 NuxtJS SSR、TypeScript 和 vuex-module-decorators 一起工作。
我尝试遵循官方 nuxt 网站和vuex-module-decorators 的指南,但没有任何效果......
这是我的代码:
// store/CommonModule.ts
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
@Module({
name: 'CommonModule',
namespaced: true,
stateFactory: true,
})
export default class CommonModule extends VuexModule {
message: string = 'hi'
@Mutation
public SET_MESSAGE(val: string) {
this.message = val
}
}
Run Code Online (Sandbox Code Playgroud)
// store/index.ts
import Vuex from 'vuex'
import CommonModule from '~/store/CommonModule'
export function createStore() {
return new Vuex.Store({
modules: {
CommonModule,
},
})
}
Run Code Online (Sandbox Code Playgroud)
// …Run Code Online (Sandbox Code Playgroud)