微信小程序 - (下拉)加载更多数据
注意和后端配合就行了,前端也只能把数据拼接起来!
无论是下拉加载还是加载更多,一样的道理!
注意首次加载传递参数
注意每次加载数据数
wxml
1 2 3 4 5 6 7 8 9 10 11 12 13 | <view class = 'table-rank' > <view class = 'tables center' wx: for = "{{ranklist}}" wx: for -index= "idx" wx:key= "prototype" > <view class = 'stage-rank' > {{idx+1}} </view> <view class = 'name' >{{item.name}}</view> <view class = 'price' >{{item.count}}</view> </view> </view> <view class = 'more' > <button loading= "{{loading}}" disabled= "{{disabled}}" catchtap= "setLoading" >{{loadText}}</button> </view> |
js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | var app = getApp().globalData; Page({ data: { loadText: '加载更多' , ranklist: [], count: 1 }, onLoad: function (res) { // 首次加载:传参数num:0 let num = 0; let _page = this ; let uid = wx.getStorageSync( 'uinfo' ).uid; wx.request({ url: 'url' , data: { uid, num }, header: { 'content-type' : 'application/json' }, method: 'GET' , dataType: 'json' , responseType: 'text' , success(res) { _page.setData({ ranklist: res.data.all_list, me: res.data.me }); } }) }, //点击 加载更多 按钮 setLoading(e) { let _this = this ; let _page = this ; // 暂存数据 let ranklistBefore = _this.data.ranklist; let uid = wx.getStorageSync( 'uinfo' ).uid; // 每次加载数据条数(10) let num = _this.data.count++ * 10; wx.request({ url: app.api.simulation_ranking, data: { uid, num }, header: { 'content-type' : 'application/json' }, method: 'GET' , dataType: 'json' , responseType: 'text' , success(res) { // 每次加载数据,请求一次就发送10条数据过来 let eachData = res.data.all_list; if (eachData.length == 0) { wx.showToast({ title: '没有更多数据了!~' , icon: 'none' }) } else { wx.showToast({ title: '数据加载中...' , icon: 'none' }) } _page.setData({ loadText: "数据请求中" , loading: true , ranklist: ranklistBefore.concat(eachData), loadText: "加载更多" , loading: false , }); } }) } }); |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现