错误:[vuex]期望将字符串作为类型,但未定义

Yeo*_*_Li 3 javascript ecmascript-6 vue.js vuex

正在学习Vuex。我针对示例项目文档编写了一个简单的登录页面,但是当我尝试使用动作功能时,开发人员工具只是警告我

错误信息

这是我的代码:

src / views / Login.vue

handleLogin (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // to do
          this.$store.dispatch('user/login', this.loginUser)
        } else {
          ......
          })
        }
      })
Run Code Online (Sandbox Code Playgroud)

src / store / index.js

import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/User/user'
// import info from './modules/info'

Vue.use(Vuex)

export default new Vuex.Store({
  strict: false,
  modules: {
    user,
    // info
  }
})
Run Code Online (Sandbox Code Playgroud)

/src/store/modules/User/actions.js

export const userActions = {
  login({commit}, loginUser) {
    commit(LOGIN)
    axios.post(`${ API_BASE_USER }/login`, loginUser)
         .then(res => {
           console.log(res)
           if (res.status == 200) { commit(LOGIN_SUCCESS, res.data) }
           else { commit(LOGIN_FAILURE, res.data) }
         })
  }
}
Run Code Online (Sandbox Code Playgroud)

/src/store/modules/User/user.js

import { userActions } from './actions'
import { userMutations } from './mutations'
export default {
  namespaced: true,
  state: {
    token: ''
  },
  actions: Object.assign({}, userActions),
  mutations: Object.assign({}, userMutations)
}
Run Code Online (Sandbox Code Playgroud)

Yeo*_*_Li 7

我知道了。原点突变-type.jsexport const LOGIN = LOGIN

但是正确的mutation-type.js应该是 export const LOGIN = 'LOGIN'


Mem*_*ord 6

当您在$store.commit()不提供参数的情况下调用时也会发生这种情况