InfiniteLoading 无限加载

列表滚动到底部自动加载更多数据。

效果

使用方法

<template>
<div style="background:#f6f6f6">
<lc-title title="无限加载"></lc-title>
<lc-infiniteloading @loadmore="onInfinite" :is-show-mod="true" :has-more="isHasMore" :is-loading="isLoading"
:threshold="200">
<ul class="list" >
<li class="list-item" v-for="(item, index) of dataScroll" :key="index">我是测试数据{{index + 1}}</li>
</ul>
</lc-infiniteloading>
</div>
</template>

<script>
import LcTitle from '_mods/title.vue';
import Category from '_mods/category.vue';
export default {
components: { LcTitle, Category },
data() {
return {
dataScroll: new Array(30),
page: 2,
num: 30,
isHasMore: true,
isLoading: false,
isErr: false,
timer: null
};
},
methods: {
onInfinite () {
this.isLoading = true;
this.timer = setTimeout(() => {
if (this.page <= 5) {
this.dataScroll = new Array(this.num * this.page);
this.page = this.page + 1;
} else {
this.isHasMore = false;
}
this.isLoading = false;
}, 100);
}
},
destroyed() {
clearTimeout(this.timer);
}
};
</script>

<style lang="less" scoped>
.list{
padding-top: 10px;
.list-item{
height: 50px;
border: 1px solid mix(#0785DB, #FFF, 40%);
margin-bottom: 10px;
font-size: 12px;
color: mix(#0785DB, #FFF, 80%);
line-height: 50px;
text-align: center;
background-color: #fff;
}
}
</style>

可配置参数

字段 说明 类型 默认值
hasMore 是否还有更多数据 Boolean true
isLoading 是否加载中 Boolean false
threshold 距离底部多远加载 Number 200

事件回调

字段 说明 回调参数
loadmore 继续加载的回调函数 -