微信小程式分頁懶載入
阿新 • • 發佈:2019-02-19
程式碼示例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: '沒有更多資料'}) }},