import { onMounted, onBeforeUnmount, ref } from 'vue';
const logs = ref(null) // 绑定到滚动的盒子上
onMounted(() => {
window.addEventListener('scroll', handleScroll, true);
})
onBeforeUnmount(() => {
window.removeEventListener('scroll', handleScroll, true);
})
const handleScroll = () => {
// 总数据条数大于当前已加载条数
if (state.logsTotal > state.logsArr.length) {
var scrollHeight = logs.value.scrollHeight
var scrollTop = logs.value.scrollTop
var clientHeight = logs.value.clientHeight
//滚动条滚到最底部
if (scrollHeight - clientHeight == scrollTop) {
... // 在这里调用加载数据的方法
}
}
}
vue3 滚动到底部触发方法
于 2023-07-31 16:30:13 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)