vuex 中的 this.$store undefined

问题:

在router.js中使用vuex的commit()方法,出现报错!!!

vuex 中的 this.$store undefined_第1张图片

 

解决思路:

1、对比其他调用vuex的store,(发现分别在vue组件、(router.js)js文件中,进行了调用)

vuex 中的 this.$store undefined_第2张图片

vuex 中的 this.$store undefined_第3张图片

2、在main.js中 console.log(store),结果发现vuex已经引入,可正常使用

vuex 中的 this.$store undefined_第4张图片

vuex 中的 this.$store undefined_第5张图片

结果:

js 中不能直接 this.$store.commit,vue组件中可以。把this.$store.commit ,转换为store.commit,并进行import引入,即可 

vuex 中的 this.$store undefined_第6张图片

你可能感兴趣的:(javascript,前端,vue.js)