如何实现上拉刷新下拉加载

1、在pages.json文件     开启 ​​enablePullDownRefresh​​

"enablePullDownRefresh": true

2、ArRoval是下拉刷新组合的数据

这部分是自己封装的接口

options.url = myApi.listApproval;
            options.method = 'POST';
            options.data = that.persone;
            that.$request(options).then(res => {

})

(适用于小程序token过期验证,有需要请查看,之前写的有点搂,简单的方式以后更新uni-app 接口封装 微信小程序token 过期无痕获取_uni-app的token过期,重新获取token_My&Liu的博客-CSDN博客

微信登录请查看

    如何实现微信小程序微信授权登录_My&Liu的博客-CSDN博客

<!-- 审核页面 -->
<template>
	<view>
	</view>
</template>

<script>
import myApi from '@/utils/app.js';
export default {
	data() {
		return {
			
			ArRoval: [],
			persone: {
				pageNo: 1,
				pageSize: 10
			},
			loadingTxt: '暂无数据'
		};
	},
	created() {
		let that = this;
		that.loadDate();
	},
	// 下拉刷新数据
	onPullDownRefresh() {
		let that = this;
		that.loadDate('resh');
	},
	// 上拉数据加载
	onReachBottom() {
		let timer = null;
		let that = this;
		//阻止重复加载
		if (timer !== null) {
			clearTimeout(timer);
		}
		timer = setTimeout(() => that.LoadMore(), 500);
	},
	methods: {
		loadDate(resh) {
			let that = this;
			let options = {};
			options.url = myApi.listApproval;
			options.method = 'POST';
			options.data = that.persone;
			that.$request(options).then(res => {
				if (res.code == '200') {
					that.ArRoval = res.result;
					if (resh) {
						uni.stopPullDownRefresh();
					}
				}
			});
		},
		LoadMore() {
			let that = this;
			let options = {};
			that.loadingTxt = '加载中';
			that.persone.pageNo++;
			options.url = myApi.listApproval;
			options.method = 'POST';
			options.data = that.persone;
			that.$request(options).then(res => {
				if (res.code == '200') {
					if (that.ArRoval.length >= res.total) {
						that.loadingTxt = '数据已加载完';
						return that.loadingTxt;
					}
					that.ArRoval = that.ArRoval.concat(res.result);
					//停止下拉样式
					uni.stopPullDownRefresh();
					//隐藏标题读取
					uni.hideNavigationBarLoading();
				}
			});
		}
	}
};
</script>

<style lang="scss">
.clflexBtn {
	width: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	align-self: center;
}
</style>

3、全部代码

<!-- 审核页面 -->
<template>
	<view>
		<!-- 提示框 -->
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<!-- 导航栏 -->
		<u-sticky bgColor="#fff"><u-tabs :list="list" @click="Onroval"></u-tabs></u-sticky>
		<!-- 人员列表 -->
		<!-- 已审批 -->
		<Apoved v-if="current == 1" />
		<!-- 未审批 -->
		<penroval v-if="current == 0" :ArRoval="ArRoval" />
		<!-- 下拉刷新 -->
		<u--text type="info" align="center" :text="loadingTxt" />
	</view>
</template>

<script>
import myApi from '@/utils/app.js';
import { tabs } from '@/pages/pagesA/mine/mine.js';
// 已审批
import Apoved from '@/pages/pagesA/components/mine/Apoved.vue';
// 未审批
import penroval from '@/pages/pagesA/components/mine/penroval.vue';
export default {
	components: {
		penroval,
		Apoved
	},
	data() {
		return {
			list: tabs.List,
			current: 0,
			ArRoval: [],
			persone: {
				pageNo: 1,
				pageSize: 10
			},
			loadingTxt: '暂无数据'
		};
	},
	created() {
		let that = this;
		that.loadDate();
	},
	// 下拉刷新数据
	onPullDownRefresh() {
		let that = this;
		that.loadDate('resh');
	},
	// 上拉数据加载
	onReachBottom() {
		let timer = null;
		let that = this;
		//阻止重复加载
		if (timer !== null) {
			clearTimeout(timer);
		}
		timer = setTimeout(() => that.LoadMore(), 500);
	},
	methods: {
		loadDate(resh) {
			let that = this;
			let options = {};
			options.url = myApi.listApproval;
			options.method = 'POST';
			options.data = that.persone;
			that.$request(options).then(res => {
				if (res.code == '200') {
					that.ArRoval = res.result;
					if (resh) {
						that.Notify('success','刷新成功')
						uni.stopPullDownRefresh();
					}
				}
			});
		},
		Notify(type, mes) {
			let that = this;
			that.$refs.uNotify.show({
				type: type,
				message: mes
			});
		},
		LoadMore() {
			let that = this;
			let options = {};
			that.loadingTxt = '加载中';
			that.persone.pageNo++;
			options.url = myApi.listApproval;
			options.method = 'POST';
			options.data = that.persone;
			that.$request(options).then(res => {
				if (res.code == '200') {
					if (that.ArRoval.length >= res.total) {
						that.loadingTxt = '数据已加载完';
						return that.loadingTxt;
					}
					that.ArRoval = that.ArRoval.concat(res.result);
					//停止下拉样式
					uni.stopPullDownRefresh();
					//隐藏标题读取
					uni.hideNavigationBarLoading();
				}
			});
		},
		// tabs事件
		Onroval(item) {
			let that = this;
			let inx = item.index;
			that.current = inx;
		}
	}
};
</script>

<style lang="scss">

</style>

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

My&Liu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值