使用Vuex时报错提示Cannot read property ‘commit‘ of undefined终极解决
使用Vuex时报错提示Cannot read property 'commit' of undefined`,检查了很久终于发现是版本冲突的问题!
   ·  
 场景:
背景:使用Vuex时报错提示Cannot read property 'commit' of undefined
  踩坑:检查了很久,终于发现是版本冲突的问题!
解决
先检查store.js是否在main.js中注册了
import store from './store'
new Vue({
    render: h => h(App),
    store,
    router
}).$mount('#app')
版本:
如果仍然出现commit找不到的问题,检查vue和vuex的版本
以我的项目版本为例,vue:2.6.14 和 vuex 4.1
  网上找了很多,说是vuex 4.X 的版本适用于vue3,所以这里改一下版本
npm uninstall vuex  --force or --legacy-peer-deps
npm install vuex@3  --force or --legacy-peer-deps
安装上vuex 3.6.2 ,最后成功解决报错!
更多推荐
 
 



所有评论(0)