我切換到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'
}
你能試試這個嗎