data: { pageNo: 1,//當前頁 pageSize: 10,//每頁條數 count:'',//總條數 orderList: [], }, onLoad: function () { var that = this; var data = `${that.data.type}/${that.data.pageSize}/${that.data.pageNo}`; that.getOrderList(data); }, //訂單列表 getOrderList(data) { var that = this; var orderList = that.data.orderList; wx.showLoading({ title: '加載中', }) wx.request({ url: `${host.orderList}/${data}`, header: { "content-type": "application/json", }, success: function (res) { console.log(res); if (res.data.code == 0) { if (res.data.data.list && res.data.data.count > orderList.length) { var arr = res.data.data.list; arr.forEach(item => { orderList.push(item); }) that.setData({ orderList: orderList, count: res.data.data.count, }) } } else { wx.showToast({ icon: 'none', title: res.data.msg, }) } }, complete: function () { setTimeout(() => { wx.hideLoading(); wx.stopPullDownRefresh(); }, 500) } }) }, /** * 頁面相關事件處理函數--監聽用戶下拉動作 */ onPullDownRefresh: function () { var that = this; var data = `${that.data.type}/${that.data.pageSize}/${that.data.pageNo}`; that.getOrderList(data); }, /** * 頁面上拉觸底事件的處理函數 */ onReachBottom: function () { var that = this; var pageNo = that.data.pageNo; if (that.data.count > that.data.orderList.length){ that.setData({ pageNo: pageNo += 1, noMore: true, }) var data = `${that.data.type}/${that.data.pageSize}/${pageNo}`; that.getOrderList(data); } },
下拉觸底需要在當前頁面的json文件添加"enablePullDownRefresh": true或者在app.json window里面全局添加。