vue防抖

 

copy
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) // 进入该分支说明当前并没有在计时,那么就开始一个计时
}

 

posted @   默永  阅读(35)  评论(0编辑  收藏  举报
相关博文:
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起