UNPKG

zgg-ui

Version:

2.0.1 正式版本 基于 Vue 3、UniApp 和 TypeScript 开发的多端适配移动端 UI 组件库,旨在提供丰富的组件集合,帮助开发者快速构建多端响应式的移动应用界面

37 lines (32 loc) 824 B
import type { Ref } from 'vue' export const useLongPress = <T extends any[]>( event: (...args: T) => void, enabled: Ref<boolean>, longPressIntervel = 250 ) => { // 长按判断定时器 let longPressTimer: ReturnType<typeof setTimeout> | null = null // 清除长按判断定时器 const clearLongPressTimer = () => { if (longPressTimer) { clearInterval(longPressTimer) longPressTimer = null } } // 处理长按事件 const handleLongPressEvent = (...args: T) => { if (enabled.value) { event(...args) clearLongPressTimer() longPressTimer = setInterval(() => { event(...args) }, longPressIntervel) } else { event(...args) } } return { handleLongPressEvent, clearLongPressTimer, } }