【小程序开发】上拉加载更多demo
wxml:
<scroll-view class='swiper-scroll' scroll-y="{{true}}" bindscrolltolower="lower" style='height:800rpx;'>
<block wx:for="{{requestRes}}" wx:key="item" wx:for-index="idx">
<view>
<image style='width:100rpx;height:100rpx;' src="{{requestRes[idx].avatar}}" alt=""></image>
</view>
<view>{{requestRes[idx].description}}</view>
<view><text>¥<text>{{item.price}}</text></text><text>¥{{item.oldprice}}</text></view>
</block>
<view class="tips1">
<view wx:if="{{hasMore}}">
<text>玩命的加载中...</text>
</view>
<view wx:else>
<text>没有更多内容了</text>
</view>
</view>
</scroll-view>
js:
//index.js
//获取应用实例
var app = getApp()
var http = app.globalData.http
Page({
data: {
requestRes: {},
pagel: 1, // 发出的 页数
hasMore: false
},
// 触底加载数据
lower: function (e) {
console.log('kaihsi')
this.setData({
hasMore: true
})
this.loaddatal();
},
onLoad: function (option) {
var that = this
// 请求数据
wx.request({
url: 'http://cloud.topmdrt.com/api/v1/activity/goods_praise/page',
method: 'get',
data: {
currentPage: this.data.pagel,
sourceId: 2,
id: 83
},
success: function (res) {
console.log(res)
that.setData({
requestRes: res.data.response.dataList
})
}
})
},
// 发出的数据 加载
loaddatal: function () {
console.log('chufa')
var listData = this.data.requestRes;
var that = this;
var pag = this.data.pagel + 1;
wx.request({
url: 'http://cloud.topmdrt.com/api/v1/activity/goods_praise/page',
method: 'get',
data: {
currentPage: pag,
sourceId: 2,
id: 83
},
success: function (res) {
var pagel = that.data.pagel + 1;
if (res.data.response.dataList.length == 0) {
this.setData({
requestRes: res.data.response.dataList,
pagel: -1
})
return false;
}
that.setData({
pagel: pagel,
requestRes: listData.concat(res.data.response.dataList),
hasMore: false
})
// that.update()
}
})
}
})
wxss:
/**上拉加载更多**/
.tips1{
height: 60rpx;
line-height: 60rpx;
color: #999;
font-size: 21rpx;
text-align: center;
}
/* */
.minearea image {
text-align: center;
display: block;
}
.minearea {
text-align: center;
line-height: 3.2rem;
}
.page-section {
width: 76%;
margin: auto;
margin-top: 36rpx;
}
.weui-input {
border: solid 1px #e6e6e6;
height: 90rpx;
border-radius: 2rpx;
padding-left: 20rpx;
padding-right: 20rpx;
">#f5f5f5;
color: #333;
}
.page-body {
margin-top: 120rpx;
}
.page-section-title {
color: #333;
font-size: 32rpx;
padding-left: 0rpx;
}
.placeholder {
color: #cbcbcb;
}
.btn-area {
margin-top: 90rpx;
}
本文来自博客园,作者:JeckHui;
个人主页:前端实用站点推荐; 热榜资讯早读:热榜资讯-导航;
转载请注明原文链接:https://www.cnblogs.com/xiaohuizhang/p/8872231.html
分类:
小程序开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)