fix(components): [tooltip] remove mousemove listener when unmount (#11940)

Co-authored-by: Jeremy <15975785+jw-foss@users.noreply.github.com>
This commit is contained in:
zt123123 2023-03-12 14:26:51 +08:00 committed by GitHub
parent 125f5f4650
commit 6a8a5aaf3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { onMounted, onUnmounted, ref } from 'vue'
const visible = ref(false)
const triggerRef = ref({
@ -28,14 +28,19 @@ const position = ref({
right: 0,
})
onMounted(() => {
document.addEventListener('mousemove', (e) => {
position.value = DOMRect.fromRect({
width: 0,
height: 0,
x: e.clientX,
y: e.clientY,
})
const mousemoveHandler = (e) => {
position.value = DOMRect.fromRect({
width: 0,
height: 0,
x: e.clientX,
y: e.clientY,
})
}
onMounted(() => {
document.addEventListener('mousemove', mousemoveHandler)
})
onUnmounted(() => {
document.removeEventListener('mousemove', mousemoveHandler)
})
</script>