首页 > 解决方案 > Vuex 未知动作类型...不会加载我的动作

问题描述

存在未知操作类型的问题。

商店.js:

import Vue from 'vue'
import Vuex from 'vuex'
import { state } from './store/state'
import { mutations } from './store/mutations'
import { actions } from './store/actions'
import { getters } from './store/getters'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  actions,
  mutations,
  getters,
  state,
  plugins: [createPersistedState()]
})

动作.js

import { ServerAPI } from '../plugins/server-api'
import { Mutations } from './mutations'

export const Actions = {
  checkAuth: 'checkAuth',
  loadCustomers: 'loadCustomers'
}
export const actions = {
  [Actions.checkAuth] (context, payload) {
  },
  [Actions.loadCustomers] ({ commit }) {
    // context.state
    let customers = {}
    ServerAPI.getCustomers().then((response) => {
      if (response.status === 200) {
        response.data.forEach((customer) => {
          customers[customer.id] = customer
        })
        commit(Mutations.assignBulkCustomers, customers)
      }
    }).catch((error) => {
      console.log(error)
    })
    return Promise.resolve(customers)
  }
}

应用程序.vue

methods: {
      ...mapActions([
        Actions.loadCustomers,
        Actions.checkAuth
      ]),

并调用它

 this.loadCustomers()

我不知何故有这个错误。[vuex] unknown action type: loadCustomers

当我查看调试信息时,我可以看到操作没有加载,但 getter 和突变是。

标签: vuejs2vuex

解决方案


推荐阅读