【问题标题】:Vue3 with Typescript -> this object is possibly undefined带有 Typescript 的 Vue3 -> 这个对象可能是未定义的
【发布时间】:2021-07-09 01:12:14
【问题描述】:

每次我在代码中使用“this”关键字时,它都会突出显示“对象可能未定义”

【问题讨论】:

    标签: typescript vue.js vue-router vuejs3


    【解决方案1】:

    当您将数据属性定义为箭头函数时,您应该将this 作为参数传递,例如:

    data:(vm)=>{//vm represents this keyword
       return{
          ....
          productType:vm.$route.path.slice(1).split("/")[0]
      }
    }
    

    【讨论】:

    • 我可以用“this”来表示这个关键字吗?
    • 不,你不能,因为它是保留关键字
    猜你喜欢
    • 2020-05-11
    • 1970-01-01
    • 2020-08-11
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多