给vue侦听器加防抖
watch: {
//该方法会在数据变化时调用执行
//newValue新值,oldvalue老值(一般不用)
//words (newValue) {
// console.log('变化了', newValue)
//}
'obj.words' (newValue) {
//console.log('变化', newValue)
//防抖:延迟执行 -> 干啥事先等一等,延迟一会,一段时间再执行
clearTimeout(this.timer)
this.timer = setTimerout(async () => {
const res = await axios({
url: 'https://...',
params: {
words: newValue
}
})
this.result = res.data.data
},1000)
}
}