const debounce = () => {
axios.get('/api/blog/administration/spot').then(res => {
if (res.data.code == 200) {
} else {
this.$message.error(res.data.msg);
}
}).catch(error => {
this.$message.error(error.message);
})
}
if (this.timer) {
clearTimeout(this.timer) //进入该分支语句,说明当前正在一个计时过程中,并且又触发了相同事件。所以要取消当前的计时,重新开始计时
this.timer = setTimeout(() => {
debounce();
}, 300)
} else {
this.timer = setTimeout(() => {
debounce();
}, 300) // 进入该分支说明当前并没有在计时,那么就开始一个计时
}
标签:防抖,vue,debounce,res,error,timer,计时,message From: https://www.cnblogs.com/Lmyong/p/16844472.html