实现一个超简单的防抖

185 阅读1分钟

debounce(fn){
    if(this.timer){return}
	this.timer = 1
	setTimeout(()=>{
	    fn.apply(this,arguments)
	    this.timer = null
	},1000)
},

接下来在你想加防抖的方法直接调用,例:

this.debounce(this.searchkeyword)

这样1秒内连续触发也只会触发一次事件啦。