返回介绍

Ionic4 上拉分页组件 ion-infinite-scroll

发布于 2019-11-22 18:04:17 字数 6268 浏览 867 评论 0 收藏 0

Ionic4 项目中我们可以使用 Ionic4 上拉分页组件 ion-infinite-scroll 对项目进行布局。

ion-infinite-scroll 官方文档地址:https://ionicframework.com/docs/api/infinite-scroll

The Infinite Scroll component calls an action to be performed when the user scrolls a specified distance from the bottom or top of the page.

The expression assigned to the ionInfinite event is called when the user reaches that defined distance. When this expression has finished any and all tasks, it should call the complete() method on the infinite scroll instance.

Infinite Scroll Content

The ion-infinite-scroll component has the infinite scroll logic. It requires a child component in order to display content. Ionic uses its ion-infinite-scroll-content component by default. This component displays the infinite scroll and changes the look depending on the infinite scroll's state. It displays a spinner that looks best based on the platform the user is on. However, the default spinner can be changed and text can be added by setting properties on the ion-infinite-scroll-content component.

Custom Content

Separating the ion-infinite-scroll and ion-infinite-scroll-content components allows developers to create their own content components, if desired. This content can contain anything, from an SVG element to elements with unique CSS animations.

ion-infinite-scroll 用法 Usage

<ion-content>
<ion-list>
<ion-item *ngFor="let item of items; let index">
<ion-avatar slot="start">
<img [src]="'https://picsum.photos/80/80?random=' + index" alt="avatar" />
</ion-avatar>
<ion-label>{{ item }}</ion-label>
</ion-item>
</ion-list>
<ion-infinite-scroll (ionInfinite)="onIonInfinite($event)">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-content>
import { Component, OnInit } from '@angular/core';

import { InfiniteScrollCustomEvent } from '@ionic/angular';

@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.scss'],
})
export class ExampleComponent implements OnInit {
items = [];

ngOnInit() {
this.generateItems();
}

private generateItems() {
const count = this.items.length + 1;
for (let i = 0; i < 50; i++) {
this.items.push(`Item ${count + i}`);
}
}

onIonInfinite(ev) {
this.generateItems();
setTimeout(() => {
(ev as InfiniteScrollCustomEvent).target.complete();
}, 500);
}
}

ion-infinite-scroll 属性 Properties

disabled

Description

If true , the infinite scroll will be hidden and scroll event listeners will be removed.

Set this to true to disable the infinite scroll from actively trying to receive new data while scrolling. This is useful when it is known that there is no more data that can be added, and the infinite scroll is no longer needed.

Attributedisabled
Typeboolean
Defaultfalse

position

Description

The position of the infinite scroll element. The value can be either top or bottom .

Attributeposition
Type"bottom" | "top"
Default'bottom'

threshold

Description

The threshold distance from the bottom of the content to call the infinite output event when scrolled. The threshold value can be either a percent, or in pixels. For example, use the value of 10% for the infinite output event to get called when the user has scrolled 10% from the bottom of the page. Use the value 100px when the scroll is within 100 pixels from the bottom of the page.

Attributethreshold
Typestring
Default'15%'

ion-infinite-scroll 事件 Events

NameDescription
ionInfiniteEmitted when the scroll reaches the threshold distance. From within your infinite handler, you must call the infinite scroll's `complete()` method when your async operation has completed.

ion-infinite-scroll 内置方法 Methods

complete

Description

Call complete() within the ionInfinite output event handler when your async operation has completed. For example, the loading state is while the app is performing an asynchronous operation, such as receiving more data from an AJAX request to add more items to a data list. Once the data has been received and UI updated, you then call this method to signify that the loading has completed. This method will change the infinite scroll's state from loading to enabled .

Signaturecomplete() => void

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文