useSwipe
基于 TouchEvents
的响应式滑动检测。
演示
方向:无
lengthX: 0 | lengthY: 0
用法
vue
<script setup>
const el = ref(null)
const { isSwiping, direction } = useSwipe(el)
</script>
<template>
<div ref="el">
Swipe here
</div>
</template>
类型声明
显示类型声明
typescript
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 {
isPassiveEventSupported: boolean
isSwiping: Ref<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.cn/useSwipe
* @param target
* @param options
*/
export declare function useSwipe(
target: MaybeRefOrGetter<EventTarget | null | undefined>,
options?: UseSwipeOptions,
): UseSwipeReturn
来源
贡献者
Anthony Fu
丶远方
Amirreza Zarkesh
lstoeferle
Anthony Fu
Alexey Istomin
Jelf
云游君
Shinigami
Alex Kozack
变更日志
v10.7.0
于 2023 年 12 月 5 日v10.1.0
于 2023 年 4 月 22 日v10.0.0-beta.4
于 2023 年 4 月 13 日4d757
- feat(types)!: 将 MaybeComputedRef
重命名为 MaybeRefOrGetter
v10.0.0-beta.0
于 2023 年 3 月 14 日f285c
- fix!: 使用字面量表示滑动方向,而不是枚举