useSwipe
基于 TouchEvents
的响应式滑动检测。
示例
方向:none
水平长度:0 | 垂直长度:0
用法
vue
<script setup>
const el = ref(null)
const { isSwiping, direction } = useSwipe(el)
</script>
<template>
<div ref="el">
在这里滑动
</div>
</template>
类型声明
显示类型声明
typescript
export type UseSwipeDirection = "up" | "down" | "left" | "right" | "none"
export interface UseSwipeOptions extends ConfigurableWindow {
/**
* 将事件注册为被动事件
*
* @default true
*/
passive?: boolean
/**
* @default 50
*/
threshold?: number
/**
* 滑动开始时的回调函数
*/
onSwipeStart?: (e: TouchEvent) => void
/**
* 滑动过程中的回调函数
*/
onSwipe?: (e: TouchEvent) => void
/**
* 滑动结束时的回调函数
*/
onSwipeEnd?: (e: TouchEvent, direction: UseSwipeDirection) => void
}
export interface UseSwipeReturn {
/**
* @deprecated No longer need this Vue 3's browser targets all supporting passive event listeners.
*
* This flag will always return `true` and be removed in the next major version.
*/
isPassiveEventSupported: boolean
isSwiping: Ref<boolean>
direction: ComputedRef<UseSwipeDirection>
coordsStart: Readonly<Position>
coordsEnd: Readonly<Position>
lengthX: ComputedRef<number>
lengthY: ComputedRef<number>
stop: () => void
}
/**
* 响应式滑动检测。
*
* @see https://vueuse.org/useSwipe
* @param target
* @param options
*/
export declare function useSwipe(
target: MaybeRefOrGetter<EventTarget | null | undefined>,
options?: UseSwipeOptions,
): UseSwipeReturn
源码
贡献者
Anthony Fu
一纸忘忧
丶远方
Amirreza Zarkesh
lstoeferle
Fernando Fernández
IlyaL
Anthony Fu
Alexey Istomin
Jelf
云游君
Shinigami
Alex Kozack
更新日志
v12.4.0
on 1/10/2025v12.0.0-beta.1
on 11/21/2024v11.3.0
on 11/21/2024v10.7.0
on 12/5/2023v10.1.0
on 4/22/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
v10.0.0-beta.0
on 3/14/2023f285c
- fix!: use literal for swipe direction instead of enum