vuex报错问题: Cannot read property 'dispatch' of undefined

389 阅读1分钟
1. 子组件内,调用mapActions报错解决方法

引入   import store from '../../store';

调用actions的方法:

store.dispatch('setFileName', this.$route.params.fileName).then(() => {
            this.initEpub();
   })

这样就可以调到了。

注意 .检查main.js文件,引入

import store from "./store/index"

之前那种

import {mapGetters} from 'vuex' ;
 ...mapGetters(['fileName'])
  this.$store.dispatch('setFileName',this.$route.params.fileName).then(()=>{
  this.initEpub();