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/useSwipe.md
1---2category: Sensors3---45# useSwipe67Reactive swipe detection based on [`TouchEvents`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent).89## Usage1011```vue12<script setup lang="ts">13import { useSwipe } from '@vueuse/core'14import { useTemplateRef } from 'vue'1516const el = useTemplateRef('el')17const { isSwiping, direction } = useSwipe(el)18</script>1920<template>21<div ref="el">22Swipe here23</div>24</template>25```2627## Type Declarations2829```ts30export type UseSwipeDirection = "up" | "down" | "left" | "right" | "none"31export interface UseSwipeOptions extends ConfigurableWindow {32/**33* Register events as passive34*35* @default true36*/37passive?: boolean38/**39* @default 5040*/41threshold?: number42/**43* Callback on swipe start44*/45onSwipeStart?: (e: TouchEvent) => void46/**47* Callback on swipe moves48*/49onSwipe?: (e: TouchEvent) => void50/**51* Callback on swipe ends52*/53onSwipeEnd?: (e: TouchEvent, direction: UseSwipeDirection) => void54}55export interface UseSwipeReturn {56isSwiping: ShallowRef<boolean>57direction: ComputedRef<UseSwipeDirection>58coordsStart: Readonly<Position>59coordsEnd: Readonly<Position>60lengthX: ComputedRef<number>61lengthY: ComputedRef<number>62stop: () => void63}64/**65* Reactive swipe detection.66*67* @see https://vueuse.org/useSwipe68* @param target69* @param options70*/71export declare function useSwipe(72target: MaybeRefOrGetter<EventTarget | null | undefined>,73options?: UseSwipeOptions,74): UseSwipeReturn75```76