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