uni.createIntersectionObserver 在自定義組件中無(wú)法獲取到對(duì)應(yīng)的dom節(jié)點(diǎn):
uni.createIntersectionObserver().relativeTo('.consult_title').observe('#consultNotice', (res) => {
//目前這種方式在開發(fā)者工具中會(huì)報(bào) Node '.consult_title' is not found Node '#consultNotice' is not found
});
根據(jù)微信文檔描述在自定義組件中必須用傳遞this劈彪;
在這里插入圖片描述
uniapp的文檔有說(shuō)明如何傳入this
在這里插入圖片描述
然而在vue3中是摒棄了this,這就需要通過(guò)vue3新增的API獲取我們所需要的this:
//getCurrentInstance
import {getCurrentInstance} from 'vue'
setup(){
const _this = getCurrentInstance(); // 通過(guò)getCurrentInstance得到我們想要的this,并把this傳入createIntersectionObserver中
//_this.proxy
uni.createIntersectionObserver(_this.proxy).relativeTo('.consult_title').observe('#consultNotice', (res) => {});
}
如果此文對(duì)你有用請(qǐng)動(dòng)動(dòng)你的小手點(diǎn)個(gè)贊哄啄!謝謝Q烙健V遣!证膨!