第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

angular里使用iscroll時(shí)如何refresh?

angular里使用iscroll時(shí)如何refresh?

Angular的項(xiàng)目,引入了iscroll,d.ts文件也寫好了,可以初始化沒問題,但是當(dāng)組件更新時(shí),需要調(diào)用IScroll.refresh(),根據(jù)以往用其他MVVM框架的經(jīng)驗(yàn),直接在視圖更新完畢的生命周期方法里調(diào)用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)    }    //.... } 但此時(shí)問題出現(xiàn)了,iscroll加載后在滑動(dòng)時(shí)會(huì)無限次觸發(fā)ngAfterViewChecked()(控制臺(tái)不斷打印出123),導(dǎo)致視圖無法正確刷新,請(qǐng)問有遇到過這種問題嗎,是如何解決的呢?
查看完整描述

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ù)中吧


查看完整回答
反對(duì) 回復(fù) 2018-10-27
?
梵蒂岡之花

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()

}


查看完整回答
反對(duì) 回復(fù) 2018-10-27
  • 2 回答
  • 0 關(guān)注
  • 1268 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)