vuex报错 this.$store显示undefined

调试vuex的时候 发现报以下错误,并且打印 this.$store 显示是undefined

报错:
[Vue warn]: Error in render: “TypeError: Cannot read properties of undefined (reading ‘state’)”
TypeError: Cannot read properties of undefined (reading ‘state’)
vuex报错

问题原因:

  1. vuex 和 vue 版本号不对应, vue2 对应vuex3, vue3 对应vuex4(去package.json文件中查看)
  2. store.js中 new Vuex.Store() Store 要大写 ,Vuex.store这种写法可能也会报错
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐