坑vue报错

26次阅读

共计 425 个字符,预计需要花费 2 分钟才能阅读完成。

报错

__WEBPACK_IMPORTED_MODULE_1_vuex__.a.store is not a constructor

store.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.store({   // 注意这个 store
  state:{lists:[]
  },
  mutations:{addItem(state,value){state.lists.push(value)
    }
  },
  actions:{}})

解决

上面 new Vuex.store
写成 new Vuex.Store
首字母要大写

这个报错的是_vuex2.default.store 不是一个构造函数因为在我们用 vuex 的时候需要将用到的 actions,mutations 模块最终导出,在导出的时候 new Vuex.Store 中的 Store 小写了,这里的一定要大写, 就相当于我们在使用构造函数 (类) 的时候首字母要大写

正文完
 0