1.在需要监听的组件的data中设定数值
data() {
return {
timer: null,
scrollT: 0,
stopscroll: 0
};
},
2.在methods中设定方法
handleScroll() {
clearTimeout(this.timer);
this.timer = setTimeout(this.ScrollEnd, 500);
this.scrollT = document.documentElement.scrollTop || document.body.scrollTop;
},
ScrollEnd() {
this.stopscroll = document.documentElement.scrollTop || document.body.scrollTop;
if (this.stopscroll == this.scrollT) {
console.log("滚动已结束");
}
},
3.在mounted中绑定handScroll函数
window.addEventListener("scroll", this.handleScroll);