🚀
头像

默永


人生就像骑单车,想保持平衡就得往前走。

vue防抖

2021-11-22 09:03:56 230 💗 1 @默永
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) // 进入该分支说明当前并没有在计时,那么就开始一个计时
}
    目录导航