debounce

防抖函数,在指定时间内多次触发只执行最后一次

用法

debounce 函数用于防抖处理,在指定时间内多次触发只执行最后一次。

import { debounce } from '@movk/core'

const debouncedSearch = debounce((query: string) => {
  console.log('搜索:', query)
}, 300)

// 连续调用,只有最后一次会执行
debouncedSearch('a')
debouncedSearch('ab')
debouncedSearch('abc') // 只有这次会在300ms后执行

API

debounce<T>(func, wait)

防抖函数,在指定时间内多次触发只执行最后一次。

参数

func
T extends (...args: any[]) => any required
需要防抖的函数。
wait
number required
防抖延迟时间(毫秒)。

返回值

返回值
(...args: Parameters<T>) => void
防抖处理后的函数。

Changelog

7c832 — refactor!: 重构模块架构,拆分 utils 为专业化模块

Copyright © 2024 - 2026 YiXuan - MIT License