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 中,列表 触底加载 是一种常见的用户体验优化技术,用于在用户滚动到列表 底部时自动加载更多数据。

相关推荐
万少9 分钟前
鸿蒙创新赛 HarmonyOS 6.0.0(20) 关键特性汇总
前端
还有多远.27 分钟前
jsBridge接入流程
前端·javascript·vue.js·react.js
蝶恋舞者34 分钟前
web 网页数据传输处理过程
前端
非凡ghost36 分钟前
FxSound:提升音频体验,让音乐更动听
前端·学习·音视频·生活·软件需求
w2sfot44 分钟前
Passing Arguments as an Object in JavaScript
开发语言·javascript·ecmascript
烛阴1 小时前
【TS 设计模式完全指南】从零到一:掌握TypeScript建造者模式,让你的对象构建链式优雅
javascript·设计模式·typescript
郝学胜-神的一滴1 小时前
避免使用非const全局变量:C++中的最佳实践 (C++ Core Guidelines)
开发语言·c++·程序人生
吃饭最爱1 小时前
html的基础知识
前端·html
我没想到原来他们都是一堆坏人1 小时前
(未完待续...)如何编写一个用于构建python web项目镜像的dockerfile文件
java·前端·python
搞一搞汽车电子1 小时前
S32K3平台eMIOS 应用说明
开发语言·驱动开发·笔记·单片机·嵌入式硬件·汽车