cannot read property 'dispatch' of undefined in Vuex

后端 未结 10 704
囚心锁ツ
囚心锁ツ 2020-12-30 03:51

I\'m trying to perform a dispatch on \'logOutUser\' in vuex store, and i\'m getting the following error message in respone:

TypeError: Cannot read pro

10条回答
  •  时光取名叫无心
    2020-12-30 04:11

    My guess would be either not initialized store, or wrong this context.

    For the purposes of debugging I'd try using mapActions helper vuex.vuejs.org:

    import { mapActions } from 'vuex'
    
    export default {
      methods: {
        ...mapActions({
          add: 'increment' // map `this.add()` to `this.$store.dispatch('increment')`
        })
    
        // ...
      }
    
      // ...
    }
    

提交回复
热议问题