md
This commit is contained in:
parent
dd3b50d40d
commit
b592850a0a
27
src/utils/input/debounceModule.js
Normal file
27
src/utils/input/debounceModule.js
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user