this.$store.getters.getPerms是undefined
时间: 2023-08-30 20:08:03 浏览: 53
你提到的代码 `this.$store.getters.getPerms` 返回了 `undefined`,这种情况可能是由于 `getPerms` 在 Vuex store 的 getters 中未定义引起的。请确保在你的 Vuex store 的 getters 中定义了名为 `getPerms` 的函数,并返回相应的值。另外,还需要确认你是否正确地在组件中调用了该 getter。如果以上方法都没有解决问题,可以提供更多的代码细节,以便我能够更好地帮助你。
相关问题
vuex无法获取getters属性this.$store.getters.getCurChildId undefined
可能出现这种情况的原因是,您在获取getters属性时使用了错误的语法。正确的语法应该是 this.$store.getters.getCurChildId(),即需要在属性名后面加上一对括号。
如果仍然无法获取该属性,可能是因为您还没有在store中定义该getter,您需要在store中的getters对象中定义一个名为getCurChildId的getter,如下所示:
```
const store = new Vuex.Store({
state: {
// ...
},
getters: {
getCurChildId: state => {
// ...
}
}
})
```
请确保您的getter函数返回一个值,这样才能在组件中正确地使用该getter属性。如果仍然无法解决问题,请检查您的代码是否有其他错误。
this.$store
引用提到了在Vue3 TypeScript中使用this.$store会报错。这是因为在Vue3中,Vuex的类型定义发生了一些改变,this.$store不再被认为是一个有效的属性。因此,直接使用this.$store会导致Property '$store' does not exist on type的错误。
引用介绍了this.$store.commit()和this.$store.dispatch()方法的区别。两个方法都是用来传递值给Vuex的mutation来改变state。this.$store.commit()是同步操作,通过this.$store.commit('方法名', 值)来存储值,然后通过this.$store.state.方法名来获取值。而this.$store.dispatch()是异步操作,通过this.$store.dispatch('方法名', 值)来存储值,然后通过this.$store.getters.方法名来获取值。
引用提到了解决报错this.$store.commit is not a function的方法。这可能是因为在代码中没有正确导入Vuex或者没有正确配置Vuex的store。可以参考该引用的方法来解决这个问题。
综上所述,this.$store在Vue3 TypeScript中不再被视为有效的属性。可以使用this.$store.commit()和this.$store.dispatch()来实现对Vuex的mutation和action的调用,具体取值方式也有所不同。如果遇到报错this.$store.commit is not a function,可以参考引用中的方法来解决。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vue3+ts中使用this.$store报错Property ‘$store‘ does not exist on type](https://blog.csdn.net/qq_31755699/article/details/124213551)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [vuex中this.$store.commit和this.$store.dispatch的用法](https://blog.csdn.net/weixin_44582045/article/details/121852631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [vuex 解决报错this.$store.commit is not a function的方法](https://download.csdn.net/download/weixin_38743119/12948476)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]