uniapp微信小程序uni-load-more上拉加载更多数据
1.引入uni-app中uni-load-more.vue到自己的项目import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';2.data 中定义reload: false,status: 'more',contentText: {contentdown: '上拉加载更多~',contentrefresh: '加
·
1.引入uni-app中uni-load-more.vue到自己的项目
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
2.data 中定义
reload: false,
status: 'more',
contentText: {
contentdown: '上拉加载更多~',
contentrefresh: '加载中',
contentnomore: '我是有底线的~'
},
3.在需要加载的地方写上标签
v-if=“dataList.length > 0” //判断没有数据是不加载
<uni-load-more :status="status" :icon-size="14" :content-text="contentText" v-if="dataList.length > 0" />
4.请求接口里判断加载状态
success: (result) => {
this.totalCount = result.data.total
if (result.data.total > 0) {
const dataMap = result.data.list
this.dataList = this.reload ? dataMap : this.dataList.concat(dataMap);
this.reload = false;
} else {
this.dataList = [];
}
if (this.totalCount == this.dataList.length) {
this.reload = false;
this.status = 'noMore'
}
}
5.监听下拉到底部事件
onReachBottom() {
if (this.totalCount > this.dataList.length) {
this.status = 'loading';
setTimeout(() => {
this.pageNum++
this.getMonthTask();//执行的方法
}, 1000)//这里我是延迟一秒在加载方法有个loading效果,如果接口请求慢的话可以去掉
} else { //停止加载
this.status = 'noMore'
}
},
更多推荐
已为社区贡献4条内容
所有评论(0)