Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useMousePressed.md
1---2category: Sensors3---45# useMousePressed67Reactive mouse pressing state. Triggered by `mousedown` `touchstart` on target element and released by `mouseup` `mouseleave` `touchend` `touchcancel` on window.89## Basic Usage1011```ts12import { useMousePressed } from '@vueuse/core'1314const { pressed } = useMousePressed()15```1617Touching is enabled by default. To make it only detects mouse changes, set `touch` to `false`1819```ts20import { useMousePressed } from '@vueuse/core'21// ---cut---22const { pressed } = useMousePressed({ touch: false })23```2425To only capture `mousedown` and `touchstart` on specific element, you can specify `target` by passing a ref of the element.2627```vue28<script setup lang="ts">29import { useMousePressed } from '@vueuse/core'30// ---cut---31import { useTemplateRef } from 'vue'3233const el = useTemplateRef('el')3435const { pressed } = useMousePressed({ target: el })36</script>3738<template>39<div ref="el">40Only clicking on this element will trigger the update.41</div>42</template>43```4445## Component Usage4647```vue48<template>49<UseMousePressed v-slot="{ pressed }">50Is Pressed: {{ pressed }}51</UseMousePressed>52</template>53```5455## Type Declarations5657```ts58export interface UseMousePressedOptions extends ConfigurableWindow {59/**60* Listen to `touchstart` `touchend` events61*62* @default true63*/64touch?: boolean65/**66* Listen to `dragstart` `drop` and `dragend` events67*68* @default true69*/70drag?: boolean71/**72* Add event listeners with the `capture` option set to `true`73* (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#capture))74*75* @default false76*/77capture?: boolean78/**79* Initial values80*81* @default false82*/83initialValue?: boolean84/**85* Element target to be capture the click86*/87target?: MaybeComputedElementRef88/**89* Callback to be called when the mouse is pressed90*91* @param event92*/93onPressed?: (event: MouseEvent | TouchEvent | DragEvent) => void94/**95* Callback to be called when the mouse is released96*97* @param event98*/99onReleased?: (event: MouseEvent | TouchEvent | DragEvent) => void100}101/** @deprecated use {@link UseMousePressedOptions} instead */102export type MousePressedOptions = UseMousePressedOptions103export interface UseMousePressedReturn {104pressed: ShallowRef<boolean>105sourceType: ShallowRef<UseMouseSourceType>106}107/**108* Reactive mouse pressing state.109*110* @see https://vueuse.org/useMousePressed111* @param options112*/113export declare function useMousePressed(114options?: UseMousePressedOptions,115): UseMousePressedReturn116```117