mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-08 01:58:52 +08:00
refactor: 优化debounce默认值写法
This commit is contained in:
parent
b8b03c352b
commit
6c20b4329e
@ -542,13 +542,12 @@ type DebounceOptions = {
|
||||
trailing?: boolean // 是否在延迟时间结束时调用函数
|
||||
}
|
||||
|
||||
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceOptions = {}): T {
|
||||
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceOptions = { leading: false, trailing: true }): T {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
||||
let lastArgs: any[] | undefined
|
||||
let lastThis: any
|
||||
let result: ReturnType<T> | undefined
|
||||
const leading = isDef(options.leading) ? options.leading : false
|
||||
const trailing = isDef(options.trailing) ? options.trailing : true
|
||||
const { leading, trailing } = options
|
||||
|
||||
function invokeFunc() {
|
||||
if (lastArgs !== undefined) {
|
||||
|
||||
@ -79,7 +79,7 @@ const reactiveState = reactive({
|
||||
setColumns
|
||||
})
|
||||
|
||||
const scroll = debounce(handleScroll, 100, { leading: false }) // 滚动事件
|
||||
const scroll = debounce(handleScroll, 100) // 滚动事件
|
||||
|
||||
provide('wdTable', reactiveState)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user