diff --git a/src/utils/useDebounce.js b/src/utils/useDebounce.js index 237e21d..17494ac 100644 --- a/src/utils/useDebounce.js +++ b/src/utils/useDebounce.js @@ -6,6 +6,7 @@ export function useDebounce(fn, delay = 500, immediate = false) { let instance = getCurrentInstance() // 获取当前组件实例 const debounced = (...args) => { + // 接收所有传入的参数 if (timer) clearTimeout(timer) if (immediate && !timer) { @@ -14,7 +15,7 @@ export function useDebounce(fn, delay = 500, immediate = false) { } timer = setTimeout(() => { - if (!immediate) fn.apply(this, args) + if (!immediate) fn.apply(this, args) // 将参数透传给原始函数 timer = null // 清理timer引用 }, delay) } @@ -50,7 +51,7 @@ export function useThrottle(fn, delay = 1000) { const now = Date.now() if (now - lastCall < delay) return lastCall = now - fn(...args) + fn(...args) // 将参数透传给原始函数 } return throttled