函数节流

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

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

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

  return function (...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}

 

posted @ 2020-02-05 14:29  ladybug7  阅读(126)  评论(0)    收藏  举报