cannot read property 'dispatch' of undefined in Vuex

后端 未结 10 730
囚心锁ツ
囚心锁ツ 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:06

    That's because you probably didn't add store option to the root instance of Vue. By providing it you will be able to access store from all of root's child components. Therefore your root instance should look like this:

    import store from './store'
    
    const app = new Vue({
      /* .. other properties .. */
      store
    })
    

    Now you can freely use this.$store within your components.

提交回复
热议问题