Skip to content
# throttle(func, wait = 500) 在事件被触发后,立即执行函数,然后在一段时间内(间隔时间)不再执行,直到间隔时间过后才能再次执行。

支持平台 ​

安卓iosweb微信小程序
√√√√

组件方式使用(推荐) ​

组件内置节流功能,通过 :throttle 和 :tdTime 属性控制:

html
<template>
	<view>
		<t-button type="primary"
				  :throttle="true"
				  :tdTime="1000"
				  @click="onClick">快速点击测试触发时机</t-button>
	</view>
</template>

<script setup>
	function onClick() {
		uni.showToast({
			title: '事件被执行'
		})
	}
</script>

API方式使用 ​

javascript
import { TuiDebounce } from '@/uni_modules/tui-common'
const deb = new TuiDebounce()
deb.throttle(() => {
	// 执行逻辑
}, 500)