监听滚动到底部事件:
javascript
function isScrollToBottom() {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
const clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
return scrollTop + clientHeight >= scrollHeight-100;
}
在mounted里增加监听scroll:
javascript
mounted() {
let _this = this
this.dataList = this.originData
window.addEventListener('scroll', function () {
// 判断是否滚动到了底部
if (isScrollToBottom() && !_this.loading) {
_this.loading = true;
// 加载更多内容
_this.loadmore()
}
});
},
这样就可以触底loadmore了。。
参考链接: