直接上代码
<div id="myElement"><div>
watch: {
// recordList是组件传递的数据,不用管
recordList(list) {
if (list) {
this.$nextTick(() => {
var bady = document.getElementById('myElement')
bady.onscroll = () => {
// 获取距离顶部的距离
var scrollTop = bady.scrollTop
if (scrollTop !== 0 && this.oldv == 0) {
this.oldv = scrollTop
}
// 获取可视区的高度
var windowHeight = bady.clientHeight
// 获取滚动条的总高度
var scrollHeight = bady.scrollHeight
if (scrollTop + windowHeight >= scrollHeight) {
console.log('到达底部了')
}
if (scrollTop == 0 && this.oldv !== 0) {
console.log('到达头部了')
}
}
})
}
},
},