节流函数

132 阅读1分钟
  onSearch = val => {
    console.log(val)
    this.setState({
      searchAppCode: val,
      page: 1,
      pubConfNameList: []
    },()=>{
    // 请求的函数
      this.getPubConfInfo()
    })
  };

 debounce = (fun, delay) => {
  let timer //定时器
  
  return  (args) => {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => { 
       fun(args)
    }, delay)
  }
}
 // 调用方法
   onSearch = { this.debounce(this.onSearch, 2000) }