小程序分页加载数据
// pages/billlist/index.js
const app = getApp();
Page({/*頁(yè)面的初始數(shù)據(jù)*/data: {page: 1,loading: false,loadtxt: '正在加載...',list: []},/*生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載*/onLoad: function (options) {this.setData({option: options})this.getlist();},getlist: function () {app.fetch.newData.result({ API_URL: app.globalData.api + 'getGoldFlowList.do?ipage=' + this.data.page + '&ipagesize=15'}).then(({ data }) => {if (data.object && data.object.list && data.object.list.length) {let list = data.object.list;for (let i = 0; i < list.length; i++) {list[i].c_create_datetime = app.util.formatDate(new Date(list[i].c_create_datetime));}this.setData({list: this.data.list.concat(list)})if (this.data.page == data.iTotalPage) {this.setData({loading: true,loadtxt: '無(wú)更多內(nèi)容'})} else {this.setData({loading: false,loadtxt: '正在加載...'})}} else if (this.data.list.length) {this.setData({loading: true,loadtxt: '無(wú)更多內(nèi)容'})} else {this.setData({loading: true,loadtxt: '暫無(wú)數(shù)據(jù)'})}}).catch(e => {this.setData({loading: false,loadtxt: '數(shù)據(jù)加載異常'})})},/*頁(yè)面上拉觸底事件的處理函數(shù)*/onReachBottom: function () {if (!this.data.loading) {this.setData({loading: true,page: this.data.page + 1})this.getlist()}}
})
總結(jié)
- 上一篇: 使用 webpack 4 和 Babel
- 下一篇: 分享一个Vant Weapp小程序UI组