[英]Object is possibly 'undefined' in Vue with this.$refs
我切换到 typescript 突然我的一些代码出现错误:
Object is possibly 'undefined'
typescript版本是3.2.1
这是代码:
this.$refs[`stud-copy-${index}`][0].innerHTML = 'Link Copied'
我试图添加一个 if 条件来检查它是否未定义但没有运气:
if (this.$refs[`stud-copy-${index}`] !== undefined) {
this.$refs[`stud-copy-${index}`][0].innerHTML = 'Link Copied'
}
你能试试这个吗
(this.$refs[`stud-copy-${index}`] as HTMLElement[])[0].innerHTML = 'Link Copied'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.