vuejs2 - 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 和突变是。
解决方案
推荐阅读
- javascript - 使用 BigInt 将 Int64 从 .net 服务传递到 Javascript
- c# - 当字符串中只有两个时获取特定字符的第二个索引
- xcode - TouchId 和 FaceId 授权条件
- ios - 我正在尝试以编程方式创建 UI,但滚动视图和文本视图无法正常工作
- java - 按升序对连接和分组的记录进行排序
- angular - Angular Universal 是否提供 JIT 或 AOT 编译?
- java - 如何在不实际重新加载 JSP 页面的情况下单击下一个/上一个按钮逐个打印数据(arraylist 的对象)?
- google-sheets - 如何在 Google Data Studio 中同时使用 SUM () 和 CASE () 计算总金额?
- java - 使用 Lucene Query 测试文档是否匹配
- php - 如何将验证码添加到邮件表单