小程序
1.微信开发者工具
页面上拉触底事件的处理函数
onReachBottom: function () {
if(this.data.datalist.length === parseInt(this.total)){
return;
}
console.log("到底了")
this.page++
wx.request({
url: `http://localhost:3000/goods?_page=${this.page}&_limit=8`,
success:(res)=>{
console.log(res.data)
this.setData({
datalist:[...this.data.datalist,...res.data]
})
}
})
},
2.uniapp
uniapp-scroll-view
<scroll-view class="info-box" scroll-y="true" scroll-with-animation="true" @scrolltolower="upToBottom">
......
</scroll-view>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/66e69f732704ddf4076ed88188add06b.png)
网站
methods: {
upToBottom () {
var DOM = document.documentElement || document.body
var contentHeight = DOM.scrollHeight
var scrollTop = DOM.scrollTop
var viewHeight = DOM.clientHeight
if (scrollTop / (contentHeight - viewHeight) === 1) {
console.log('滚动条到底部')
}
}
},
mounted () {
window.addEventListener('scroll', this.upToBottom, false)
},
beforeDestroy () {
window.removeEventListener('scroll', this.upToBottom)
},