函数节流

使用setTimeout将touchmove等事件延时,可以提高性能。

在搜索功能中也可以使用函数节流

export function debounce(func, delay = 200) {
  let timer

  return function (...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}
原文地址:https://www.cnblogs.com/ladybug7/p/12263680.html