業務中遇到這個問題,百度搜索了一下,沒有好的方案就自己寫了一個。
在mounted中監聽對應的div滾動事件
document.querySelector('.content-box').addEventListener("scroll", this.scrollToTop);
在方法中執行,最後記得移除監聽
scrollToTop(){
let el=document.querySelector('.content-box');
const scrollTop = el.scrollTop;
const scrollHeight = el.scrollHeight;
if ((el.offsetHeight + scrollTop) - scrollHeight == 0) {//如果置底
// 需要執行的代碼
}
},
distoryed() {
document.querySelector('.content-box').removeEventListener("scroll", this.scrollToTop);
},