报错如图

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]的出错