ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
小程序提供了,onPullDownRefresh和onReachBottom两个事件函数监听下拉和上拉事件函数。提示加载中,取消加载中 ~~~ data: { enterpriseList: [], pageNo: 1, //页数 pageSize: 10, // 条数 }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { this.setData({ //刷新操作初始化数据 pageNo: 1, list: [], isEmpty: true }) this.queryData(); //查询数据 }, ~~~ ~~~ /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { var pageNum = this.data.pageNo; if (pageNum < this.data.totalPageCnt) { this.setData({ pageNo: pageNum + 1 //设置下一页 }) this.queryData(); //查询数据 } else { wx.showToast({ title: "没有更多数据了", duration: 1000, icon: 'none', mask: true }) } }, ~~~ 查询数据方法 ~~~ //查询数据 queryData: function() { var that = this; var pageNo = this.data.pageNo; var pageSize = this.data.pageSize; wx.showLoading({ title: '加载中...', }); wx.request({ url: app.globalData.pubSiteUrl + 'pubsite-company/companylist', //上线的话必须是https,没有appId的本地请求貌似不受影响 method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT header: { 'Content-Type': "application/x-www-form-urlencoded", 'Cookie': 'SESSION=' + wx.getStorageSync("sessionId") }, // 设置请求的 header data: { pageIndex: pageNo, pageSize: pageSize }, success: function(res) { app.consoleLog("请求数据成功"); app.consoleLog(res.data) wx.hideLoading(); //隐藏加载中提示 if (res.data.dataList.length > 0) { if (that.data.enterpriseList.isEmpty) { that.setData({ // 设置页面列表的内容 enterpriseList: res.data.dataList, }) } else { that.setData({ // 设置页面列表的内容 enterpriseList: that.data.enterpriseList.concat(res.data.dataList), totalPageCnt: res.data.totalPageCnt }) } } else { wx.showToast({ title: "没有更多数据了", duration: 1000, icon: 'none', mask: true }) } }, fail: function() { wx.hideLoading(); //隐藏加载中提示 wx.showToast({ title: "请求失败!", duration: 1000, icon: 'none', mask: true }) }, complete: function() { // complete } }) }, ~~~