uniapp中uni-load-more的使用

1 引入uniloadmore

import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

components: {uniLoadMore},

2 data中写的内容

reload: false,
status: 'more',
contentText: {
		contentdown: '上拉加载更多~',
		contentrefresh: '加载中',
		contentnomore: '我是有底线的~'
},

3 template里面写的内容

<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'
		}
},

完毕!!!

你可能感兴趣的:(前端,vue,前端日常笔记,uni-app,vue,小程序)