no message

This commit is contained in:
2025-09-12 17:56:35 +08:00
parent 2612f3c45d
commit 6cdc7e416e
2 changed files with 25 additions and 2 deletions
+21 -1
View File
@@ -1,4 +1,7 @@
let timeout = null;
let timer;
let flag;
export default {
@@ -37,7 +40,24 @@ export default {
}
return tmpTime;
}, 
debounce(func,wait = 1000,immediate = true){
// 清除定时器
if (timeout !== null) clearTimeout(timeout)
// 立即执行,此类情况一般用不到
if (immediate) {
const callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) typeof func === 'function' && func()
} else {
// 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法
timeout = setTimeout(() => {
typeof func === 'function' && func()
}, wait)
}
}
}