报错如图

vuex报错: [vuex] Expects string as the type, but found undefined.

检查了好久,发现

import * as types from '../mutation-types'
const actions = { add({commit}){ commit(types.ADD) } } const mutations = { [types.ADD](state){ state.count++ } }

这里的 [types.ADD] 如果换成

const actions = {
  add({commit}){
    commit('ad')
  }
}
const mutations = {
  ad(state){
    state.count++
  }
}

就不会报错

判断结果:[types.ADD]这里有问题,

于是 检查mutation-types.js文件

vuex报错: [vuex] Expects string as the type, but found undefined.

 

原来是ADD等号右边没有加引号的缘故。导致[types.ADD]的出错

 

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2021-07-13
  • 2021-06-04
  • 2021-06-06
  • 2021-12-29
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2021-09-17
  • 2021-05-30
  • 2022-12-23
  • 2021-10-19
  • 1970-01-01
  • 2022-12-23
  • 2021-11-02
相关资源
相似解决方案