第一种
watch: {
quickSearch(val) {
let timer = null
if (timer !== null) clearTimeout(timer)
timer = setTimeout(() => {
this.loading = true
this.init()
}, 2000)
// this.$emit('sonParameters', val)
}
}
第二种
const delay = (function () {
let timer = 0
return function (callback, ms) {
clearTimeout(timer)
timer = setTimeout(callback, ms)
}
})()
quickSearch(val) {
delay(() => {
this.loading = true
this.init()
}, 1000)
},
我不太懂其中原理,哪位前辈能给说说