fix backTop 返回顶部 无法生效

实测 document.documentElement document.body  无法触发滚动事件
 removeEventListener 需要使用addEventListener 相同的函数(引用地址)

Signed-off-by: pplokijuhyg <1162963624@qq.com>
This commit is contained in:
pplokijuhyg 2022-11-11 08:54:19 +00:00 committed by Gitee
parent 4abe693301
commit 4caef2eb5d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -174,7 +174,7 @@ const getScrollParent = (
}
}
// @ts-ignore
return document.documentElement || document.body || window;
return window;
};
//
@ -189,17 +189,17 @@ const throttle = (func: Function, wait: number) => {
}
};
};
const callback = throttle(handleScroll, 300);
onMounted(() => {
if (!props.target) return;
scrollTarget.value = getScrollTarget();
scrollTarget.value.addEventListener("scroll", throttle(handleScroll, 300));
scrollTarget.value.addEventListener("scroll", callback);
});
onBeforeUnmount(() => {
scrollTarget.value?.removeEventListener(
"scroll",
throttle(handleScroll, 300)
callback
);
});
</script>