课程章节: 课程介绍(Vue3升级内容)
主讲老师: Sunday
课程内容:
今天学习的内容包括:
Vue3升级内容
课程收获:
1.1 心得:
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
pagenum: 1,
scrollTop: 0,
collectionDatas: [],
hasMoreData: true,
isRefreshing: false,
isLoadingMoreData: false,
IsEmpty:false
},
getMyCollectionData: function () {
var that = this;
wx.showLoading({
title: "数据加载中..."
});
var openId = '';
app.getOpenId(function (openid) {
if (openid) {
openId = openid
}
}, 'myCollection');
wx.request({
url: app.getUrl(app.globalData.getMyCollectionData),
data: {
pageNum: that.data.pagenum, //从数据里获取当前页数
pageSize: 10, //每页显示条数
openId: openId
},
success: function (res) {
// console.log(res)
var result = res.data;
if (result.result) {
var listNew = that.data.collectionDatas.concat(result.data.rows); //合并数组
that.setData({
collectionDatas: listNew,
isLoadingMoreData: false
});
if (listNew.length == 0) {
that.setData({
IsEmpty: true
});
}
if (result.data.rows.length == 0 || result.data.rows == null) {
that.setData({
hasMoreData: false
});
}
}
wx.hideLoading();
},
fail: function (err) { wx.hideLoading(); }, //请求失败
complete: function () { } //请求完成后执行的函数
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var that = this;
that.getMyCollectionData();
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
var that = this;
if (that.data.isRefreshing || that.data.isLoadingMoreData || !that.data.hasMoreData) {
return
}
var pagenum = that.data.pagenum + 1; //获取当前页数并+1
that.setData({
pagenum: pagenum, //更新当前页数
isLoadingMoreData: true
})
that.getMyCollectionData(); //重新调用请求获取下一页数据
}
})