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: '加载中',
		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'
		}
},
UniApp 是一款基于 Vue.js 的跨平台开发框架,可以用于构建微信小程序、H5应用以及更多平台。要创建一个微信朋友圈样式的基本页面,你可以按照以下步骤编写代码: 首先,在 UniApp 项目中新建一个文件夹,比如 "components",然后在该文件夹下创建一个新的.vue 文件,如 "wechatMoments.vue"。 ```html <template> <view class="moments-container"> <!-- 微信朋友圈列表 --> <uni-list class="list"> <uni-cell v-for="(item, index) in items" :key="index"> <image :src="item.avatarUrl" slot="cover"></image> <uni-cell-meta> <uni-avatar size="small" src="{{ item.userAvatar }}"></uni-avatar> <uni-cell-title>{{ item.name }} 发布了一条动态</uni-cell-title> <uni-cell-extra>{{ item.time }}</uni-cell-extra> </uni-cell-meta> <uni-text class="content">{{ item.content }}</uni-text> </uni-cell> </uni-list> <!-- 加载更多按钮 --> <view v-if="moreLoading" class="load-more">加载更多...</view> </view> </template> <script setup> import { ref } from 'vue'; const items = ref([ // 这里放置模拟的数据,实际项目中应从服务端获取数据 { avatarUrl: 'https://example.com/avatar1.jpg', name: '用户1', userAvatar: 'https://example.com/userAvatar1.png', content: '动态内容1', time: '2023-04-01' }, // ... 更多数据... ]); let moreLoading = ref(false); function loadMore() { moreLoading.value = true; setTimeout(() => { items.value.push({ // 添加新数据 }); moreLoading.value = false; }, 2000); } onLoadMore = () => { if (!moreLoading.value) { loadMore(); } }; </script> <style scoped> .moments-container { padding: 16rpx; } .list { margin-top: 16rpx; } .load-more { text-align: center; padding: 16rpx; } </style> ``` 在这个例子中,我们创建了一个包含用户头像、名字、时间、内容的基本朋友圈列表,并且添加了“加载更多”的功能。请注意,这只是一个基础示例,实际应用中你需要连接到微信提供的API或者你自己搭建的服务器来获取真实的用户数据
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值