---
title: "debounce"
description: "防抖函数，在指定时间内多次触发只执行最后一次"
seo_title: "debounce"
seo_description: "Create a debounced function that delays invoking the callback until the wait time elapses since the last call, ideal for input and resize handlers."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/async/debounce"
---
# debounce

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

## 用法

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

```ts
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

See commit history for [src/utilities/async/debounce.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/async/debounce.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
