下拉框远程搜索,防抖

防抖(debounce):当持续触发事件时,一定时间段内没有再触发事件,事件处理函数才会执行一次,如果设定的时间到来之前,又一次触发了事件,就重新开始延时。

let timeout: any = null;
const handleSearch = (e: any) => {
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    };
    const fake = async () => {
      //此处写你的请求及数据处理
    };
    timeout = setTimeout(fake, 500);
};



你可能感兴趣的:(下拉框远程搜索,防抖)