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

相关推荐
刘发财2 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶5 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶5 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol7 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路9 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide9 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter9 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸10 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live0000011 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉11 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化