uniapp懒加载插件的使用

<tempate里面使用

<uni-load-more v-if="load == 1" :loadingType="loadingType" :contentText="contentText"></uni-load-more>

<script里面导入

import uniLoadMore from '../../../components/uni-load-more.vue';
	components: {
		uniLoadMore
	},
	//data里面定义
	loadingText: '加载中...',
	loadingType: 0,
	contentText: {
		contentdown: '上拉显示更多',
		contentrefresh: '正在加载...',
		contentnomore: '没有更多数据了'
	},
	load: 0,
	page: 1,
	timer:{},
	// 上拉加载
	onReachBottom(){
		if (this.timer != null) {
			clearTimeout(this.timer)
		}
		this.timer = setTimeout(()=> {
			this.getmorenews()
		}, 1000);
	},

接下来是method里面

 //第一页
setAjax(){
	uni.request({
		url: 'https://******.com/Api/CommisionLog/index?p=' + this.page,
		method: 'POST',
		data:{
			user_id: this.user_id,
			search: this.search
		},
		header:{'Content-Type':'application/x-www-form-urlencoded'},
		success: res => {
			uni.hideLoading()
			this.res = res.data.data.data.list
			console.log(this.res)
		},
		fail: () => {},
		complete: () => {}
	});
},
 // 加载更多
getmorenews() {
	this.page++;//每触底一次 page +1
	if (this.loadingType !== 0) {//loadingType!=0;直接返回
		return false;
	}
	this.loadingType = 1;
	uni.showNavigationBarLoading();//显示加载动画
	uni.request({
		url: 'https://************.com/Api/CommisionLog/index?p=' + this.page,
		method: 'POST',
		data:{
			user_id: this.user_id,
			search: this.search
		},
		header:{'Content-Type':'application/x-www-form-urlencoded'},
		success: res => {
			uni.hideLoading()
			if (res.data.data.data.list == '') {//没有数据
				this.loadingType = 2;
				uni.hideNavigationBarLoading();//关闭加载动画
				return;
			}
			this.res = this.res.concat(res.data.data.data.list);//将数据拼接在一起
			this.loadingType = 0;//将loadingType归0重置
			uni.hideNavigationBarLoading();//关闭加载动画
		},
		fail: () => {},
		complete: () => {}
	});
},

亲测有效

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值