vuex 报 unknown action type

2024-01-09  本文已影响0人  jeneen1129

基本使用参考资料:https://www.jb51.net/article/264940.htm

问题说明

即 使用 this.$store.dispatch('user/changeUser', this.user) 会报上面的错误

问题解决

此项目中正确使用定义好的 vuex 的模块里面数据的方法如下:

import { UserModule } from '@/store/modules/form'

const select = FormModule.selectUser
UserModule.SetSelectUser(this.selectUser)   // action / mutations

定义模块

// "vuex": "3.6.2",
// index.js
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({})


// ./modules/user.ts
 import {
  VuexModule,
  Module,
  Mutation,
  Action,
  getModule,
} from 'vuex-module-decorators'
import store from '@/store'
import Vue from 'vue'

export interface IUserState {
  selectUser: any
}

@Module({ dynamic: true, store, name: 'user' })
class User extends VuexModule implements IUserState {
  selectUser: any = {}

  @Mutation
  private async SET_SELECTUSER(select: any) {
    this.selectUser = select
  }
  @Action
  public SetSelectUser(select: any) {
    this.SET_SELECTUSER(select)
  }
}

export const UserModule = getModule(User)

上一篇 下一篇

猜你喜欢

热点阅读