uniapp小程序增加加载功能

html 复制代码
<template>
	<scroll-view scroll-y="true" @scrolltolower="onReachBottom" @scroll="onPageScroll">
	<view class="content" style="background-image: url(/static/bg.jpg);height:auto!important;">
		<!-- title -->
		<view class="title">
			拍摄花絮
		</view>
		<view class="wrap">
			<!-- photo -->
			<view class="photo">
				<view class="items">
					
					<checkbox-group @change="checkboxChange" class=" flex">
						<view class="item" v-for="(item,index) in photoLists" :key="index"
							:class="{ 'active': item.checked }">
							<image :src="item.image" mode="aspectFill" @click="previewImage(item.image)"></image>
						</view>
					</checkbox-group>
				
				</view>
				<uni-load-more :status="status"></uni-load-more>
			</view>
			
		</view>
	</view>
		</scroll-view>
</template>

<script>
	import request from '@/common/request.js';
	export default {
		data() {
			return {
				activeTab: 0,
				photoLists: [], //图片列表
				list: [],
				status: 'more',
				page: 1,
				pageSize: 6,
				total: 0,
				scrollTop: 0,


			}
		},
		created() {
			this.getData();
			
		},
		

		onPullDownRefresh() {
			// console.log(22) 
			this.photoLists = [];
			this.page = 1;
			this.getData();
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	
		methods: {
			onReachBottom() {
				if (this.page * this.pageSize < this.total) {
					this.status = 'loading';
					this.page++;
					this.getData();
				} else {
					this.status = 'noMore';
				}
			},
			// 图片显示
			getData() {
				let opts = {
					url: 'api/Cream/plist',
					method: 'get'
				};
				let params = {
					page: this.page,
					pageSize: this.pageSize
				};
				uni.showLoading({
					title: '加载中'
				})
				request.httpRequest(opts,params).then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						this.photoLists.push(...res.data);
						this.total=res.count;
					}
				});
			},
			// 预览图片
			previewImage(e) {
				let img = [];
				img[0] = e;
				uni.previewImage({
					current: 0,
					urls: img,
				});
			},
		}
	}
</script>

<style>
	.title {
		color: #333;
	}

	.photo {
		margin: 80rpx auto 30rpx;
	}
</style>

uniapp 中,列表 触底加载 是一种常见的用户体验优化技术,用于在用户滚动到列表 底部时自动加载更多数据。

相关推荐
张3蜂1 天前
Python 四大 Web 框架对比解析:FastAPI、Django、Flask 与 Tornado
前端·python·fastapi
南风知我意9571 天前
【前端面试5】手写Function原型方法
前端·面试·职场和发展
qq_12498707531 天前
基于Java Web的城市花园小区维修管理系统的设计与实现(源码+论文+部署+安装)
java·开发语言·前端·spring boot·spring·毕业设计·计算机毕业设计
摘星编程1 天前
用React Native开发OpenHarmony应用:Image网络图片加载
javascript·react native·react.js
摘星编程1 天前
OpenHarmony环境下React Native:ImageBase64图片显示
javascript·react native·react.js
阿蒙Amon1 天前
TypeScript学习-第13章:实战与最佳实践
javascript·学习·typescript
froginwe111 天前
Python 条件语句
开发语言
七夜zippoe1 天前
Python统计分析实战:从描述统计到假设检验的完整指南
开发语言·python·统计分析·置信区间·概率分布
小安驾到1 天前
【前端的坑】vxe-grid表格tooltip提示框不显示bug
前端·vue.js
2601_949146531 天前
Python语音通知API示例代码汇总:基于Requests库的语音接口调用实战
开发语言·python