在vue2中使用vuex,配置时遇到的问题。
1.Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_1_vuex__.a.store is not a constructor
在store\index.js中,创建实例时,应该大写Store,vuex内部定义的大写。
const store = new Vuex.Store({
2.Property or method "$store" is not defined on the instance but referenced during render.
vuex的版本不对,获取不到store。vue3只能用vuex4版本,vue2只能用vuex3版本。
2022年2月7日之后,vue3成了默认版本,vuex4相应的也成了默认版本,vuex4只能在vue3中使用。所以对于vue2,就不能默认下载最新版本了,要
npm install vuex@3 -- save
3. Cannot read property 'state' of undefined"
在mian.js 中,创建实例时,store应该小写,也可以写成store:Store
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})