跳到主要内容

useSwipe

分类
导出大小
1.02 kB
上次更改
2 个月前

基于 TouchEvents 的响应式滑动检测。

演示

向右滑动

方向:无
长度X:0 | 长度Y:0

用法

vue
<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>

类型声明

显示类型声明
ts
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.cn/useSwipe * @param target * @param options */ export declare function
useSwipe
(
target
:
MaybeRefOrGetter
<EventTarget | null | undefined>,
options
?: UseSwipeOptions,
): UseSwipeReturn

来源

源代码示例文档

贡献者

Anthony Fu
IlyaL
Anthony Fu
丶远方
Amirreza Zarkesh
lstoeferle
NoiseFan
青椒肉丝
SerKo
Fernando Fernández
Alexey Istomin
Jelf
云游君
Shinigami
Alex Kozack

更新日志

620a9 - feat!: 移除 isPassiveEventSupported (#4886)
v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.4.0
dd316 - feat: 尽可能在所有地方使用被动事件处理程序 (#4477)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v11.3.0
1bb54 - fix: 允许在滑动期间垂直滚动 (#4323)
v10.7.0
fccf2 - feat: 升级依赖 (#3614)
v10.1.0
af3ca - fix: 忽略多次触摸 (#2996)
995aa - fix: 忽略多次触摸 (#2994)

根据 MIT 许可证发布。