Ionic4 Ionic-refresher 下拉更新

首先得建立一個列表

1.首先寫構造函數

public list:any[]=[];
constructor() {
  for(var i=0;i<10;i++){
       this.list.push(`我是第${i}條數據`);
}
}

2.首頁循環遍歷:

<ion-list>
 <ion-item *ngFor="let item of list">
    <ion-label>{{item}}</ion-label>
  </ion-item>
</ion-list>

在這裏插入圖片描述

加一個下拉顯示
<ion-refresher slot="fixed" (ionRefresh)="doRefresh($event)">
   <ion-refresher-content
    pullingIcon="arrow-dropdown"
     pullingText="Pull to refresh"
     refreshingSpinner="bubbles"
     refreshingText="Refreshing...">
  </ion-refresher-content>
</ion-refresher>

在這裏插入圖片描述
因爲下拉的時候會出啊發doRefresh()
所以可以在方法裏面寫:

doRefresh(event){
setTimeout(()=>{
for(var i=10;i<15;i++){
    this.list.unshift(`我是第${i}條數據`);
}
  event.target.complete();
 },2000)
}

在這裏插入圖片描述

這裏也可以調用服務器上的方法。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章