安装uni-load-more插件
<template> <view class="container"> <view v-for="(item,index) in videoList" :key="index">...</view> //渲染的列表处 <view v-show="isLoadMore"> //loading加载提示处 <uni-load-more :status="loadStatus" ></uni-load-more> </view> </view> </template> <script> export default { data() { return {
//列表 videoList:[], page:1, pagesize:10, loadStatus:'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式 isLoadMore:false, //是否加载中 }; }, onl oad() { this.getVideoList() }, onReachBottom(){ //上拉触底函数 if(!this.isLoadMore){ //此处判断,上锁,防止重复请求 this.isLoadMore=true this.page+=1 this.getVideoList() } }, methods:{ getVideoList(){ uni.request({ url: `${this.$baseUrl}/api-video/getlist?page=${this.page}&pagesize=${this.pagesize}`, method: 'GET', success: res => { if(res.data.code==200){ if(res.data.data.list){ this.videoList=this.videoList.concat(res.data.data.list) if(res.data.data.list.length<this.pagesize){ //判断接口返回数据量小于请求数据量,则表示此为最后一页 this.isLoadMore=true this.loadStatus='nomore' }else{ this.isLoadMore=false } }else{ this.isLoadMore=true this.loadStatus='nomore' } }else{ //接口请求失败的处理 uni.showToast({title:res.data.msg,icon:'none'}) this.isLoadMore=false if(this.page>1){ this.page-=1 } } }, fail: () => { //接口请求失败的处理 uni.showToast({title: '服务器开小差了呢,请您稍后再试',icon:'none'}) this.isLoadMore=false if(this.page>1){ this.page-=1 } }, }); }, } </script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。