当前位置: 首页 > ai >正文

uniapp的上拉加载H5和小程序

小程序


配置

{"path": "list/course-list","style": {"navigationBarTitleText": "课程列表","enablePullDownRefresh": true,"onReachBottomDistance": 150}}

上拉拉触底钩子

onReachBottom() {var that = this;if (that.groupPage * that.showNo - that.groupTotal < 0) {setTimeout(function () {that.groupPage += 1;that.getCommodityList();//请求下页数据}, 200);} else {this.isfinish = true;console.log("数据已经加载完成")}},

data值

data() {return {imgBaseWebUrl: this.$imgBaseWebUrl,serverFileUrl: app.globalData.ossFileServer,loading: '加载中',shopList: [],flowList: [],leftList: [],dictClassifyId: "",searchText: '',//搜索关键字groupPage: 1, //列表部分当前页码groupTotal: 0, //列表部分总页码showNo: 10,//每页显示条数isfinish: false,//列表数据是否加载完成reqIng: true,//数据请求中};

getCommodityList请求数据:

//获取所有商品getCommodityList: function () {let that = this;let url = "/classSchedule/page";that.reqIng = true;that.isfinish = false;let params;if(this.searchText){params={page: that.groupPage,title:this.searchText}}else{params={page: that.groupPage}}// console.log("当前请求页码", that.groupPage)this.$http.post(url, params).then((res) => {uni.hideLoading();console.log('后端', res);if (res.code == 200) {that.flowList=res.rows;console.log('取到的数据', that.flowList)if (that.showNo >= res.total) {//只有一页数据that.isfinish = true;}} else {uni.showToast({title: res.message,icon: "none",});}that.reqIng = false;}).catch((i) => {}).finally(() => {uni.hideLoading();});},


H5


view

<template><view class="container"><!-- 可滚动视图 --><scroll-viewscroll-y:style="{ height: windowHeight + 'px' }"@scrolltolower="loadMore"><!-- 数据列表 --><view v-for="(item, index) in listData" :key="index" class="item">{{ item }}</view><!-- 加载状态提示 --><view v-if="isLoadingMore" class="loading">加载中...</view><view v-if="hasMore === false" class="no-more">没有更多了</view></scroll-view></view>
</template>

js

export default {data() {return {listData: [],           // 存储列表数据page: 1,                // 当前页码isLoadingMore: false,   // 是否正在加载中hasMore: true,          // 是否还有更多数据windowHeight: uni.getSystemInfoSync().windowHeight // 屏幕高度}},created() {this.getListData() // 初始化加载第一页数据},methods: {// &#128293; 核心:加载更多数据async loadMore() {if (!this.hasMore || this.isLoadingMore) return // 防抖:避免重复请求this.isLoadingMore = truetry {const newData = await this.fetchData({ page: this.page + 1 })if (newData.length > 0) {this.listData = [...this.listData, ...newData]this.page++} else {this.hasMore = false // 无更多数据}} catch (error) {console.error('加载失败:', error)uni.showToast({ title: '加载失败', icon: 'none' })} finally {this.isLoadingMore = false}},// 模拟API请求(实际替换为你的接口)fetchData({ page }) {return new Promise(resolve => {setTimeout(() => {// 模拟分页数据(每页5条)const startIndex = (page - 1) * 5 + 1const endIndex = page * 5const mockData = Array(5).fill().map((_, i) => `第${page}页-条目${startIndex + i}`)resolve(mockData)}, 800) // 模拟网络延迟})},// 可选:下拉刷新重置数据onPullDownRefresh() {this.page = 1this.listData = []this.hasMore = truethis.getListData()uni.stopPullDownRefresh() // 停止刷新动画},getListData() {this.fetchData({ page: this.page }).then(data => {this.listData = datathis.page++})}}
}

css

.container {width: 100%;height: 100vh;
}
.item {padding: 20rpx;border-bottom: 1px solid #f0f0f0;text-align: center;
}
.loading {text-align: center;padding: 20rpx;color: #999;
}
.no-more {text-align: center;padding: 20rpx;color: #ccc;font-size: 28rpx;
}

http://www.xdnf.cn/news/19874.html

相关文章:

  • PDF.AI-与你的PDF文档对话
  • C++虚函数虚析构函数纯虚函数的使用说明和理解
  • redisson延迟队列报错Sync methods can‘t be invoked from async_rx_reactive listeners
  • 快速排序算法详解
  • 【mysql】SQL自连接实战:查询温度升高的日期
  • 三维多相机光场扫描:打造元宇宙时代的“数字自我”
  • React学习教程,从入门到精通, React 嵌套组件语法知识点(10)
  • 公司机密视频泄露频发?如何让机密视频只在公司内部播放
  • 数据采集机器人哪家好?2025 年实测推荐:千里聆 RPA 凭什么成企业首选?
  • 机器人智能控制领域技术路线
  • 嵌入式 - 硬件:51单片机(3)uart串口
  • 【Java EE进阶 --- SpringBoot】Spring IoC
  • 鸿蒙:从图库选择图片并上传到服务器
  • 什么情况下会用到ConcurrentSkipListMap
  • 【系统架构设计(15)】软件架构设计一:软件架构概念与基于架构的软件开发
  • PDF Reader 编辑阅读工具(Mac中文)
  • Linux 常用命令全解析:从入门到实战的必备指南
  • TypeScript 增强功能大纲 (相对于 ECMAScript)
  • 如何轻松地将联系人从 Mac 同步到 iPhone
  • SQLmap 完整使用指南:环境搭建 + 命令详解 + 实操案例
  • SQL Server服务管理
  • 处理省市区excel数据加工成SQL
  • 常用的几种测试工具:selenium,jmeter,jenkins
  • 【IO】进程间通信(IPC)练习
  • Unity 的游戏循环机制
  • 66车载诊断架构 --- 从架构系统角度怎么确保整车DTC的完整性?
  • (二)文件管理-基础命令-pwd命令的使用
  • 计算机视觉(六):腐蚀操作
  • 电脑城老板不会告诉你的装机秘籍:建造者模式让你的代码高配起飞!
  • 基于深度学习的医疗器械生产备案凭证识别技术,实现从图像到结构化数据的智能转化