Vue实现防抖
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) } }

浙公网安备 33010602011771号