2 回答

TA貢獻1804條經(jīng)驗 獲得超8個贊
與react,vue不同,angular的 ngAfterViewChecked()鉤子會在視圖發(fā)生任意重繪時觸發(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()
}

TA貢獻1886條經(jīng)驗 獲得超2個贊
ngAfterViewChecked
這個hook每次在檢測組件內(nèi)部自己的視圖(view)和子組件的視圖時都會調(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.
你說的那個庫沒有使用過,不過refresh
這種刷新邏輯一般不會頻繁的觸發(fā)吧,那只需要在需要觸發(fā)的時候收到調(diào)用就可以了呀,沒有必要寫到ngAfterViewChecked
生命周期函數(shù)中吧
添加回答
舉報