亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

angular里使用iscroll時如何refresh?

angular里使用iscroll時如何refresh?

料青山看我應如是 2018-10-11 13:42:54
Angular的項目,引入了iscroll,d.ts文件也寫好了,可以初始化沒問題,但是當組件更新時,需要調用IScroll.refresh(),根據以往用其他MVVM框架的經驗,直接在視圖更新完畢的生命周期方法里調用IScroll.refresh()就行了:import * as IScroll from 'iscroll'export class Model_1{    scroll : IScroll    scroll_option = {click:true} as IScroll.IScrollOptions    constructor(){   }    ngAfterViewInit(){        this.scroll = new IScroll(".scroll-wrapper",this.scroll_option)    }    ngAfterViewChecked(){        this.scroll.refresh()        console.log(123)    }    //.... } 但此時問題出現了,iscroll加載后在滑動時會無限次觸發ngAfterViewChecked()(控制臺不斷打印出123),導致視圖無法正確刷新,請問有遇到過這種問題嗎,是如何解決的呢?
查看完整描述

2 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

ngAfterViewChecked這個hook每次在檢測組件內部自己的視圖(view)和子組件的視圖時都會調用,頻率很高的。官網也說明了:

Notice that Angular frequently calls AfterViewChecked(), often when there are no changes of interest. Write lean hook methods to avoid performance problems.

你說的那個庫沒有使用過,不過refresh這種刷新邏輯一般不會頻繁的觸發吧,那只需要在需要觸發的時候收到調用就可以了呀,沒有必要寫到ngAfterViewChecked 生命周期函數中吧


查看完整回答
反對 回復 2018-10-27
?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

與react,vue不同,angular的 ngAfterViewChecked()鉤子會在視圖發生任意重繪時觸發,并不是像其他框架觸發了render才有回調,解決方案是將重載iscroll的方法直接放置于ngAfterViewInit()中:

scrollRefresh(){

    setTimeout(()=>{

        this.scroll && this.scroll.refresh()

    },130)

}

ngAfterViewInit(){

    this.scroll = new IScroll(".scroll-wrapper", this.scroll_option)

    this.scrollRefresh()

}


查看完整回答
反對 回復 2018-10-27
  • 2 回答
  • 0 關注
  • 1271 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號