This commit is contained in:
linfso 2024-05-25 22:22:39 +08:00
parent dd3b50d40d
commit b592850a0a

View File

@ -0,0 +1,27 @@
// 节流
export function throttleFun(fn, wait = 500) {
let last, now
return function () {
now = Date.now()
if (last && now - last < wait) {
last = now
} else {
last = now
fn.call(this, ...arguments)
}
}
}
// 防抖
export function debounceFun(fn, wait = 500) {
let timer
return function () {
let context = this
let args = arguments
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
fn.apply(context, args)
}, wait)
}
}