chore(backtop): 组件卸载时移除事件监听
This commit is contained in:
parent
a2b7db1418
commit
d27179de02
@ -5,7 +5,15 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, shallowRef, withDefaults, computed, onMounted } from "vue";
|
import {
|
||||||
|
ref,
|
||||||
|
shallowRef,
|
||||||
|
withDefaults,
|
||||||
|
computed,
|
||||||
|
onMounted,
|
||||||
|
onBeforeUnmount,
|
||||||
|
} from "vue";
|
||||||
|
import { useThrottle } from "@vueuse/core";
|
||||||
import LayIcon from "../icon/index";
|
import LayIcon from "../icon/index";
|
||||||
import "./index.less";
|
import "./index.less";
|
||||||
|
|
||||||
@ -186,6 +194,13 @@ onMounted(() => {
|
|||||||
scrollTarget.value = getScrollTarget();
|
scrollTarget.value = getScrollTarget();
|
||||||
scrollTarget.value.addEventListener("scroll", throttle(handleScroll, 300));
|
scrollTarget.value.addEventListener("scroll", throttle(handleScroll, 300));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
scrollTarget.value?.removeEventListener(
|
||||||
|
"scroll",
|
||||||
|
throttle(handleScroll, 300)
|
||||||
|
);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user