-
-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
<script setup lang="ts">
import { ref } from 'vue'
// Implement ...
function useEventListener(target: HTMLElement | Window, event: keyof HTMLElementEventMap, callback: any) {
target.addEventListener(event, callback)
}
// Implement ...
function useMouse() {
const x = ref(0)
const y = ref(0)
useEventListener(window, "mousemove", (e: MouseEvent) => {
const { clientX, clientY } = e
x.value=clientX
y.value=clientY
})
return {
x,
y
}
}
const { x, y } = useMouse()
</script>
<template>Mouse position is at: {{ x }}, {{ y }}</template>