uni-app上拉加载配合插件(LoadMore 加载更多.)完成
html
<scroll-view class="scroll-y list" enableBackToTop="true" scroll-y @scrolltolower="loadMore()">
<view class="scroll_item" v-for="(item,index) in list" :key="index">
{{item.name}}
</view>
<view class="" v-show="isLoadMore">
<uni-load-more :status="status"></uni-load-more>
</view>
</scroll-view>
js
import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
export default {
data() {
return {
list:[], //列表
pageSize: 10,//每页条数
pageIndex: 1,//当前页
total: 0,//总条数
status:'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式
isLoadMore: false,//是否加载中
};
},
components:{
uniLoadMore
},
onShow() {
},
methods:{
// 列表
getList(){
HttpService.getQuestionList().then(res=>{
if(res.code == 0){
if(res.data.list.length>0){
this.total = res.data.rowCount
this.list = this.list.concat(res.data.list)
if(this.list.length >= res.data.rowCount){
this.isLoadMore = true
this.status = 'nomore'
}
}else{
this.isLoadMore = true
this.status = 'nomore'
}
uni.hideLoading();
}else{
this.isLoadMore = true
this.status = 'nomore'
uni.hideLoading();
uni.showToast({title:res.msg,icon:'none'})
}
})
},
// 下拉加载
loadMore(){
if(this.pageIndex < this.total/this.pageSize){ //此处判断,上锁,防止重复请求
this.isLoadMore = true
this.pageIndex++
this.getList()
}
},
}
}
简单例子给个参考,自用