Vue.js Vuex this.$store不是函数,但会执行此.$store.dispatch

Vue.js Vuex this.$store不是函数,但会执行此.$store.dispatch,vue.js,vuex,Vue.js,Vuex,在我的App.vue组件中,我有: mounted () { this.$store.dispatch('switchSideNav', false) ... console.log('COOKIE: ', this.$store.state('cookieAgreement')) if (!this.$store.state('cookieAgreement') ..... 这将引发一个错误: Error in mounted hook: "Typ

在我的App.vue组件中,我有:

mounted () {
   this.$store.dispatch('switchSideNav', false)
   ...
   console.log('COOKIE: ', this.$store.state('cookieAgreement'))
   if (!this.$store.state('cookieAgreement')
     .....
这将引发一个错误:

Error in mounted hook: "TypeError: this.$store.state is not a function"
在DevTools上检查Vuex时,我可以看到:

 state
    cookieAgreement:false
 getters
    getAllState: Object
       cookieAgreement: false
为什么此.store与.dispatch()匹配,而与.state()不匹配


欢迎反馈

因为“状态”不是一个函数,而“调度”是vuex存储的一个函数。State是一个javascript对象,您可以像其他javascript对象一样将其与点符号一起使用。像这样,

this.$store.state.cookieAgreement // This returns your value

this.$store.state('cookieAgreement') // This returns error since .state is not a function its an object

非常感谢,我已经好几个星期没有操纵vuex了。。。你让我头脑清醒!