代码示例
data: {
baseUrl: getApp().data.baseUrl, // 接口基路径
caseData: [],
currentPage: 1, // 设置加载的第几次,默认是第一次
pageSize: 2, // 每页条数
hasMoreData: true,
},
// 获取工程案例分页集合
getCaseData: function () {
var that = this;
wx.request({
url: that.data.baseUrl + '/api/Basics/GetProjectCaseUseForPage?PageSize=' + that.data.pageSize + '&CuruntPage=' + that.data.currentPage,
method: "POST",
header: {
"Content-Type": "application/json"
},
success: function (res) {
var list = res.data.Json.Result;
if (res.data.Json.Result.length < that.data.pageSize) {
if (res.data.Json.Result.length === 0) {
wx.showToast({
icon: "none",
title: '没有更多数据'
});
that.setData({
hasMoreData: false
})
}else {
that.setData({
caseData: list.concat(that.data.caseData),
hasMoreData: false
})
}
} else {
that.setData({
caseData: list.concat(that.data.caseData),
hasMoreData: true,
currentPage: that.data.currentPage + 1
})
}
wx.hideLoading();
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getCaseData();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.hasMoreData) {
this.getCaseData()
wx.showLoading({
title: '加载更多数据',
})
} else {
wx.showToast({
icon
:
"none"
,
title: '没有更多数据'
})
}
},