getCurrentInstance 支持訪問內(nèi)部組件實例。
vue3官網(wǎng)中提示:getCurrentInstance 只暴露給高階使用場景,典型的比如在庫中。強(qiáng)烈反對在應(yīng)用的代碼中使用 getCurrentInstance。請不要把它當(dāng)作在組合式 API 中獲取 this 的替代方案來使用。
在開發(fā)環(huán)境下使用getCurrentInstance的ctx獲取實例沒有問題,但是在線上環(huán)境會報錯,建議使用proxy代替,使用時直接將proxy解構(gòu)出來
線上環(huán)境具體代碼如下:
dom.value = currentInstance.proxy.$refs['img']