Files
stack/packages/mosaic/framework/skills/vueuse-functions/references/useSwipe.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

1.5 KiB

category
category
Sensors

useSwipe

Reactive swipe detection based on TouchEvents.

Usage

<script setup lang="ts">
import { useSwipe } from '@vueuse/core';
import { useTemplateRef } from 'vue';

const el = useTemplateRef('el');
const { isSwiping, direction } = useSwipe(el);
</script>

<template>
  <div ref="el">Swipe here</div>
</template>

Type Declarations

export type UseSwipeDirection = 'up' | 'down' | 'left' | 'right' | 'none';
export interface UseSwipeOptions extends ConfigurableWindow {
  /**
   * Register events as passive
   *
   * @default true
   */
  passive?: boolean;
  /**
   * @default 50
   */
  threshold?: number;
  /**
   * Callback on swipe start
   */
  onSwipeStart?: (e: TouchEvent) => void;
  /**
   * Callback on swipe moves
   */
  onSwipe?: (e: TouchEvent) => void;
  /**
   * Callback on swipe ends
   */
  onSwipeEnd?: (e: TouchEvent, direction: UseSwipeDirection) => void;
}
export interface UseSwipeReturn {
  isSwiping: ShallowRef<boolean>;
  direction: ComputedRef<UseSwipeDirection>;
  coordsStart: Readonly<Position>;
  coordsEnd: Readonly<Position>;
  lengthX: ComputedRef<number>;
  lengthY: ComputedRef<number>;
  stop: () => void;
}
/**
 * Reactive swipe detection.
 *
 * @see https://vueuse.org/useSwipe
 * @param target
 * @param options
 */
export declare function useSwipe(
  target: MaybeRefOrGetter<EventTarget | null | undefined>,
  options?: UseSwipeOptions,
): UseSwipeReturn;