vuex报错 this.$store显示undefined

报错:vuex报错 this.$store显示undefined,使用vuex保存数据时,发现this.$store是undefined,
打印this,发现没有$store属性。
可能存在的问题

1.store文件中的Vuex实例对象是否暴露
在这里插入图片描述

2.main.js中是否注入store
在这里插入图片描述
3.若以上均没问题,打开package.json,查看vue与vuex的版本
vue2对应vuex3,vue3对应vuex4
在这里插入图片描述
我这里就是因为版本不对应导致的,安装指定版本,重启就好了!

npm install [email protected] --save

猜你喜欢

转载自blog.csdn.net/qq_45791799/article/details/127494783