uniapp中uni-load-more的使用

94 篇文章 2 订阅
84 篇文章 0 订阅

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

完毕!!!

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
在 `uniapp` 使用 `scroll-view` 组件时,下拉刷新的内容可以通过设置 `enablePullDownRefresh` 属性来实现。而下拉复位则可以通过 `scroll-view` 组件的 `scroll-view-refresher` 插槽来实现。 具体步骤如下: 1. 在 `scroll-view` 组件上添加 `refresher-enabled` 属性,并设置为 `true`,表示开启下拉刷新功能。 2. 在 `scroll-view` 组件上添加 `refresher-threshold` 属性,并设置为下拉刷新的阈值,即下拉到多少距离才触发下拉刷新。 3. 在 `scroll-view` 组件添加一个 `scroll-view-refresher` 插槽,用于显示下拉刷新的内容。 4. 在 `scroll-view-refresher` 插槽添加一个 `uni-load-more` 组件,用于下拉复位。 完整示例代码如下: ``` <scroll-view refresher-enabled refresher-threshold="80" @scrolltoupper="onRefresh"> <scroll-view-refresher> <!-- 下拉刷新的内容 --> <view>下拉刷新...</view> <uni-load-more :show="isLoading" :text="loadingText"></uni-load-more> </scroll-view-refresher> <!-- scroll-view 的内容 --> <view>scroll-view 内容</view> </scroll-view> ``` 其,`onRefresh` 方法用于在下拉刷新时触发,可以在该方法进行下拉刷新的操作。 ``` methods: { onRefresh() { // 下拉刷新操作 this.isLoading = true; this.loadingText = '正在刷新...'; // 模拟刷新完成 setTimeout(() => { this.isLoading = false; this.loadingText = '刷新成功'; }, 2000); } } ``` 在 `onRefresh` 方法,通过设置 `isLoading` 和 `loadingText` 属性来控制 `uni-load-more` 组件的显示和文本。当下拉刷新完成时,将 `isLoading` 设置为 `false`,并将 `loadingText` 设置为刷新成功的文本。此时,`uni-load-more` 组件会隐藏,同时 `scroll-view` 组件会自动进行下拉复位。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

第7个前端

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

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

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

打赏作者

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

抵扣说明:

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

余额充值