【问题标题】:How do you properly dispatch an action in vuex? Getting error [vuex] unknown action type in Chrome你如何在 vuex 中正确地调度一个动作?在 Chrome 中获取错误 [vuex] 未知操作类型
【发布时间】:2020-06-25 19:44:59
【问题描述】:

我正在尝试使用 vuex 将一些数据添加到一个安静的端点,并且 Chrome 不断抛出以下错误:vuex.esm.js?2f62:438 [vuex] unknown action type: POST_REGISTER - 你可以提供任何帮助/见解提供将非常有帮助。

这是我的设置。

在 vuex 模块中:

import actions from './actions.js'
export default {
actions: {}
}

在 actions.js 中:

import client from '@/services/authService.js'

export const POST_REGISTER = 'POST_REGISTER'

export default {
    [POST_REGISTER]: (context, data) => client.post('auth/register', data)

}

在 authService.js 中

import axios from 'axios'

export default axios.create({
    baseURL: '/api/v1/'
})

我来自 vue 组件的调用:

import {POST_REGISTER} from "@/store/auth/actions"
methods: {
  createOrUpdate: function(login) {
    this.login.username = login.username
    this.login.password = login.password
    this.$store.dispatch(POST_REGISTER, this.login)
    }
  }
}

【问题讨论】:

    标签: vue.js vuex


    【解决方案1】:

    看起来您从未在 vuex 模块中真正使用过 actions 导入。请尝试以下操作:

    import actions from './actions.js'
    export default {
    actions
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 2021-07-21
      • 2019-03-13
      • 2022-01-23
      • 2022-01-02
      • 2019-10-28
      • 2021-06-26
      • 2020-09-27
      相关资源
      最近更新 更多