- 首先写了个公共办法publicNextPage,因为别的页面可能也须要上滑加载下一页,所以封装了一下,先引入
const { publicNextPage } = require('../../util/public.js')
- 而后页面里监听页面滚动到底部
onReachBottom() { publicNextPage( this.data.pageIndex, this.data.pageCount, (newPageIndex)=>{ if(newPageIndex){ this.getList(this.data.pageSize, newPageIndex) this.setData({ pageIndex:newPageIndex }) }else{ console.log('曾经是最初一页!'); } }) }
- 更新参数后申请列表
getList(pageSize,pageIndex) { let param = { pageSize, pageIndex } myAjax('getList', 'POST', param, (res) => { if (res.list) { let newList = this.data.list.concat(res.list) // 连贯数组 this.setData({ list:newList, pageCount:res.pageCount }) } })}
- publicNextPage办法如下:
export const publicNextPage = (pageIndex, pageCount, cb) => { pageIndex++ if (pageIndex < pageCount) { cb(pageIndex) } else { cb() }}