首页 > 其他分享 >Vue实现防抖

Vue实现防抖

时间:2022-09-30 12:34:11浏览次数:59  
标签:防抖 Vue 实现 delay fn timeout getSearchSuggest

 data () {
    return {
    // 用于保存防抖的定时器
      timeout: null,
        }
    }
methods: {
    // 防抖函数
    debounce (fn, delay) {
      if (this.timeout) {
        clearTimeout(this.timeout)
      }
      this.timeout = setTimeout(() => {
        // this.getSearchSuggest()
        fn()
      }, delay)
    },
   }
watch:{
    //监听输入框的输入
    serchInputText(){
    //传入要防抖执行的函数,延时时间
    this.debounce(this.getSearchSuggest, 500)
    }
}

 

标签:防抖,Vue,实现,delay,fn,timeout,getSearchSuggest
From: https://www.cnblogs.com/haiyang-/p/16744539.html

相关文章