在做小程序,使用上拉加载数据的时候碰到了些问题,记录一下。
上拉加载数据和一般的分页原理其实是一样的,也是达到某个条件后,请求新的数据或者在显示的数组里添加新的数据。
onReachBottom
{
"window": {
"onReachBottomDistance": 50
}
}
需要在页面配置触发高度。
但是在这个方法在
<scroll-view scroll-y class="scrollPage" bindscrolltolower="getData">
</scroll-view>
getData: function () {
if (!this.data.isBottom) {
let data = [];
var num = this.data.current_num
num += 3;
for (var i = num - 2; i < num + 1; i++) {
if (i < this.data.list.length) {
data.push(this.data.list[i])
} else {
this.setData({
isBottom: true
})
}
}
this.setData({
show_list: this.data.show_list.concat(data),
current_num: num
})
}
},