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) // 进入该分支说明当前并没有在计时,那么就开始一个计时
}
本文来自博客园,作者:默永,转载请注明原文链接:https://www.cnblogs.com/Lmyong/p/16844472.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步