---
title: "throttle"
description: "节流函数，在指定时间内多次触发只执行第一次"
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/async/throttle"
---
# throttle

> 节流函数，在指定时间内多次触发只执行第一次

## 用法

`throttle` 函数用于节流处理，在指定时间内多次触发只执行第一次。

```ts
import { throttle } from '@movk/core'

const throttledScroll = throttle((event: Event) => {
  console.log('滚动事件处理')
}, 100)

// 监听滚动事件，每100ms最多执行一次
window.addEventListener('scroll', throttledScroll)
```

## API

### `throttle<T>(func, limit)`

节流函数，在指定时间内多次触发只执行第一次。

### 参数

**func** (`T extends (...args: any[]) => any`) *required*: 需要节流的函数。

**limit** (`number`) *required*: 节流时间间隔（毫秒）。

### 返回值

**返回值** (`(...args: Parameters<T>) => void`): 节流处理后的函数。

## Changelog

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

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/async/throttle.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
