useMouse
Track pointer coordinates as reactive values for a cursor-following hint or canvas interaction.
Edit the code and the preview updates as you type.
What it does
A hover card, drawing surface or coordinate readout needs the pointer position to update without wiring and cleaning up a global move listener yourself.
The playground is a small, runnable example. Change the code and try the interaction before copying it into an app.
The code
import { useMouse } from '@vueuse/core'
const { x, y } = useMouse()
// Use x and y in a tooltip or canvas overlay.Where you'd use it
- Cursor-following tooltips and labels
- Canvas drawing coordinates
- A position readout for an editor
In Nuxt (and other gotchas)
The composable is safe in setup during SSR; browser listeners are attached on the client. Coordinates may begin at their initial values before a pointer event, so do not use them to produce server-only markup.
When not to use it
Skip global pointer tracking if CSS hover or a local pointer event on one element is enough. High-frequency coordinate updates can trigger expensive rendering; throttle downstream work for costly calculations.
Links
- Official useMouse docs for every option and type
- Source code on GitHub