vue3如何移除当前组件(封装的触底组件,请求方法都在此组件中)的scroll监听事件?
onMounted(() => {
onReachBottom()
})
onBeforeUnmount(() => {
window.removeEventListener('resize', getWindowResize)window.removeEventListener('scroll', onBottom)
})
// 触底函数
const onReachBottom = () => {
window.addEventListener('scroll', onBottom)
}
// 触底相应函数
const onBottom = () => {
// 获取可视高度let clientHeight = document.documentElement.clientHeight;
// 获取滚动高度
let scrollTop = document.documentElement.scrollTop
// 滚动条高度
let scrollHeight = document.documentElement.scrollHeight
// console.log(clientHeight + scrollTop);
// console.log(scrollHeight);
if (clientHeight + scrollTop + 500 >= scrollHeight && !loading.value) {
console.log('触底了')
loading.value = true
const instance = LoadingPlugin({
attach: () => content.value,
showOverlay: false,
size: '20px',
});
page.value++
let mold = ref('')
if (props.mold == 'new') {
mold.value = 'new'
} if (props.mold == 'hot') {
mold.value = 'hot'
} if (props.mold == 'mine') {
mold.value = 'mine'
}
getGallery(page.value, mold.value).then(res => {
console.log(res);
if (res.status == 'ok') {
instance.hide();
list.value.push(...res.data)
loading.value = false
}
})
}
}
以上是 vue3如何移除当前组件(封装的触底组件,请求方法都在此组件中)的scroll监听事件? 的全部内容, 来源链接: utcz.com/p/934856.html