防抖(debounce):当持续触发事件时,一定时间段内没有再触发事件,事件处理函数才会执行一次,如果设定的时间到来之前,又一次触发了事件,就重新开始延时。
let timeout: any = null;
const handleSearch = (e: any) => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
};
const fake = async () => {
//此处写你的请求及数据处理
};
timeout = setTimeout(fake, 500);
};
<Select
filterOption={false}
style={{ width: '300px' }}
placeholder="请输入用户手机号码"
onSearch={async (e) => handleSearch(e)}
onClear={() => { handleClear() }}
showSearch
allowClear
>...</Select>