Vue——vue项目安装使用vuex时报错(vuex报错:Property or method “$store“ is not defined on the instance but referen)

问题:在vue2中使用vuex
vuex报错:Property or method “$store“ is not defined on the instance but referenced during render.

**解决方法:**
vuex的版本不对,获取不到store。vue3只能用vuex4版本,vue2只能用vuex3版本。

202227日之后,vue3成了默认版本,vuex4相应的也成了默认版本,vuex4只能在vue3中使用。所以对于vue2,就不能默认下载最新版本了,要

**npm install vuex@3 -- save** 

注意⚠️:
原因:
Vue 2.x和Vuex 4.x版本不对应
Vue 3 匹配 Vuex 4 ,Vue 2 匹配 Vuex 3
解决办法:
卸载原来安装的vuex4

npm uninstall vuex --save

安装vuex3

npm install vuex@3 --save


如果报错: **Cannot read property 'state' of undefined"**
在mian.js 中,创建实例时,store应该小写,也可以写成store:Store
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值