1. 程式人生 > >vuex報錯: [vuex] Expects string as the type, but found undefined.

vuex報錯: [vuex] Expects string as the type, but found undefined.

報錯如圖

檢查了好久,發現

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檔案

 

原來是ADD等號右邊沒有加引號的緣故。導致[types.ADD]的出錯