vue中搜素监听防止抖动的处理
原创
©著作权归作者所有:来自51CTO博客作者wx58f59a601fad5的原创作品,请联系作者获取转载授权,否则将追究法律责任
watch {
searchVal (newVal, oldVal) {
if (this.timer) {
clearTimeout(this.timer)
}
this.timer = setTimeout(() => {
// 发送请求
this.getList(newVal)
}, 300)
}
}
优化
watch {
searchVal (newVal, oldVal) {
this.timer && clearTimeout(this.timer)
this.timer = setTimeout(() => this.getCards(newVal), 300)
}
}