【问题标题】:Property XXX does not exit on type 'Computed' using Typescript使用 Typescript 的“计算”类型上不存在属性 XXX
【发布时间】:2022-01-03 05:25:56
【问题描述】:

代码运行并在浏览器的控制台中打印出 true。但是在我的本地服务器上,我收到错误Property 'authorities' does not exist on type 'Computed'. 我是 Typescript 和 Vuex 的新手。我检查了一下,isAdmin 是一个具有数组权限的对象

这是我的代码

export default {
    name: "UserSettingsTabs",
      computed: {
    ...mapGetters({
      preferences: 'tab/preferences',
      administrations: 'tab/administrations',
      isAdmin: 'auth/currentUser'
    }),
    isUserAdmin() : boolean{
      console.log(this.isAdmin.authorities.includes('Admin'));
      return this.isAdmin.authorities.includes('Admin');
    }   }, }

【问题讨论】:

    标签: typescript vuex vuejs3


    【解决方案1】:

    这是因为您使用的是mapGetters,它将isAdmin 解析为<Computed>

    这是here 讨论的一些可能的解决方案

    如果您对简单的解决方案感到满意,您可以将this.isAdmin as IIsAdmin 与您的自定义界面或类型一起使用。

    您也可以使用从 vuex 中提取值的计算函数,而不是使用 mapGetters。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-01
    • 2017-07-28
    • 2018-12-24
    • 2021-03-24
    • 2020-05-08
    • 2018-12-04
    • 2023-04-02
    • 2018-08-17
    相关资源
    最近更新 更多