2 回答

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
ngAfterViewChecked
這個(gè)hook每次在檢測(cè)組件內(nèi)部自己的視圖(view)和子組件的視圖時(shí)都會(huì)調(diào)用,頻率很高的。官網(wǎng)也說明了:
Notice that Angular frequently calls AfterViewChecked(), often when there are no changes of interest. Write lean hook methods to avoid performance problems.
你說的那個(gè)庫沒有使用過,不過refresh
這種刷新邏輯一般不會(huì)頻繁的觸發(fā)吧,那只需要在需要觸發(fā)的時(shí)候收到調(diào)用就可以了呀,沒有必要寫到ngAfterViewChecked
生命周期函數(shù)中吧

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
與react,vue不同,angular的 ngAfterViewChecked()
鉤子會(huì)在視圖發(fā)生任意重繪時(shí)觸發(fā),并不是像其他框架觸發(fā)了render才有回調(diào),解決方案是將重載iscroll的方法直接放置于ngAfterViewInit()
中:
scrollRefresh(){
setTimeout(()=>{
this.scroll && this.scroll.refresh()
},130)
}
ngAfterViewInit(){
this.scroll = new IScroll(".scroll-wrapper", this.scroll_option)
this.scrollRefresh()
}
- 2 回答
- 0 關(guān)注
- 1268 瀏覽
添加回答
舉報(bào)