InfiniteLoading
InfiniteLoading (무한 로딩)
목록을 끝까지 스크롤하면 다음 데이터를 자동으로 더 불러오는 컴포넌트예요. has-more로 더 불러올 데이터가 있는지 알려 주고, 더 이상 없을 때의 안내 문구도 설정할 수 있어요.
출처: 문서
본문
소개 (Intro)
목록의 맨 아래까지 스크롤하면 자동으로 더 많은 데이터를 로딩해요.
설치 (Install)
import { createApp } from 'vue'
import { InfiniteLoading } from '@nutui/nutui'
const app = createApp()
app.use(InfiniteLoading)
기본 사용법 (Basic Usage)
:::demo
<template>
<nut-infinite-loading v-model="infinityValue" :has-more="hasMore" @load-more="loadMore">
<div class="test" v-for="(item, index) in sum" :key="index">{{ index }}</div>
</nut-infinite-loading>
</template>
<script setup>
import { ref } from 'vue'
const cycle = ref(0)
const tabsValue = ref(0)
const sum = ref(24)
const infinityValue = ref(false)
const hasMore = ref(true)
const loadMore = (done) => {
setTimeout(() => {
sum.value = sum.value + 24
cycle.value++
if (cycle.value > 2) hasMore.value = false
infinityValue.value = false
}, 1000)
}
</script>
<style>
.test {
padding: 12px 0 12px 20px;
border-top: 1px solid #eee;
}
</style>
:::
로딩 문구 커스터마이즈 (Custom loading copywriting)
:::demo
<template>
<nut-infinite-loading
v-model="infinityValue"
load-txt="Loading..."
load-more-txt="End~"
:has-more="hasMore"
@load-more="loadMore"
>
<div class="test" v-for="(item, index) in sum" :key="index">{{ index }}</div>
</nut-infinite-loading>
</template>
<script setup>
import { ref } from 'vue'
const cycle = ref(0)
const tabsValue = ref(0)
const sum = ref(24)
const infinityValue = ref(false)
const hasMore = ref(true)
const loadMore = (done) => {
setTimeout(() => {
sum.value = sum.value + 24
cycle.value++
if (cycle.value > 2) hasMore.value = false
infinityValue.value = false
}, 1000)
}
</script>
<style>
.test {
padding: 12px 0 12px 20px;
border-top: 1px solid #eee;
}
</style>
:::
PullRefresh와 함께 사용 (Use with PullRefresh)
:::demo
<template>
<nut-infinite-loading v-model="infinityValue" :has-more="hasMore" @load-more="loadMore">
<nut-pull-refresh v-model="refresh" @refresh="refreshFun">
<div class="test" v-for="(item, index) in sum" :key="index">{{ index }}</div>
</nut-pull-refresh>
</nut-infinite-loading>
</template>
<script setup>
import { ref } from 'vue'
const cycle = ref(0)
const tabsValue = ref(0)
const sum = ref(24)
const infinityValue = ref(false)
const hasMore = ref(true)
const loadMore = (done) => {
setTimeout(() => {
sum.value = sum.value + 24
cycle.value++
if (cycle.value > 2) hasMore.value = false
infinityValue.value = false
}, 1000)
}
const refresh = ref(false)
const refreshFun = () => {
setTimeout(() => {
refresh.value = false
sum.value = 24
}, 3000)
}
</script>
<style>
.test {
padding: 12px 0 12px 20px;
border-top: 1px solid #eee;
}
</style>
:::
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | Loading status | boolean | false |
| has-more | Has more data | boolean | true |
| threshold | The loadMore event will be Emitted when the distance between the scrollbar and the bottom is less than threshold | number | 200 |
| use-capture | Whether to use capture mode | boolean | false |
| load-more-txt | "No more" text | string | Oops, this is the bottom |
| load-txt | Pull on loading text | string | Loading... |
Events
| Event | Description | Arguments |
|---|---|---|
| load-more | Emitted when continues to load | - |
| scroll-change | Real-time monitoring of roll height | height |
Slots
| Name | Description |
|---|---|
| default | Custom content |
| loading | Loading text |
| loading-icon | Custom loading icon |
| finished | Finished text |
Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value |
|---|---|
| --nut-infiniteloading-bottom-color | #c8c8c8 |
더 알아보기 (Learn more)
- 원문 문서: InfiniteLoading — NutUI v4 영문 문서
- NutUI 저장소: jd-opensource/nutui