1、首先要在json文件配置onReachBottomDistance
onReachBottomDistance: 页面上拉触底事件触发时距页面底部距离,单位为px。
json文件
{
"onReachBottomDistance": 50
}
js文件
const api = require("../../utils/api") // 引入api接口
data: {
pageSize: 10, // 显示数据量
currentPage: 1, // 当前页
list: [], // 页面数据
},
onLoad: function (options) {
const that = this
//api.demoList 页面数据接口
api.demoList({
pageNum: ++that.data.currentPage,
pageSize: that.data.pageSize
}).then(res => {
if (res.status == 200) {
that.setData({
list: res.data
})
}
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const that = this
api.demoList({
pageNum: ++that.data.currentPage, // pageNum: 需要传给后端的当前页
pageSize: that.data.pageSize //pageSize: 需要传给后端的每页显示数据量
}).then(res => {
if (res.status == 200) {
if (res.data.length < 1) {
wx.showToast({
title: '没有更多的数据了!',
icon: "none",
})
return
}
let data = res.data
console.log(res.data)
that.setData({
list: res.data
})
}
})
},