mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-02 19:28:14 +08:00
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:
parent
125f5f4650
commit
6a8a5aaf3a
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user