<template>
<ion-page>
<ion-content class="ion-padding">
<ion-button @click="toggleInfiniteScroll" expand="block"> Toggle Infinite Scroll </ion-button>
<ion-list>
<ion-item v-for="item in items" :key="item">
<ion-label>{{ item }}</ion-label>
</ion-item>
</ion-list>
<ion-infinite-scroll
@ionInfinite="loadData($event)"
threshold="100px"
id="infinite-scroll"
:disabled="isDisabled"
>
<ion-infinite-scroll-content loading-spinner="bubbles" loading-text="Loading more data...">
</ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-content>
</ion-page>
</template>
<script lang="ts">
import {
IonButton,
IonContent,
IonInfiniteScroll,
IonInfiniteScrollContent,
IonItem,
IonLabel,
IonList,
IonPage,
} from '@ionic/vue';
import { defineComponent, ref } from 'vue';
export default defineComponent({
components: {
IonButton,
IonContent,
IonInfiniteScroll,
IonInfiniteScrollContent,
IonItem,
IonLabel,
IonList,
IonPage,
},
setup() {
const isDisabled = ref(false);
const toggleInfiniteScroll = () => {
isDisabled.value = !isDisabled.value;
};
const items = ref([]);
const pushData = () => {
const max = items.value.length + 20;
const min = max - 20;
for (let i = min; i < max; i++) {
items.value.push(i);
}
};
const loadData = (ev: CustomEvent) => {
setTimeout(() => {
pushData();
console.log('Loaded data');
ev.target.complete();
if (items.value.length == 1000) {
ev.target.disabled = true;
}
}, 500);
};
pushData();
return {
isDisabled,
toggleInfiniteScroll,
loadData,
items,
};
},
});
</script>