mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-10-14 22:27:05 +00:00
21 lines
431 B
TypeScript
21 lines
431 B
TypeScript
import { customRef } from 'vue';
|
|
|
|
export function useDebouncedRef<T = any>(value: T, delay = 100) {
|
|
let timeout: TimeoutHandle;
|
|
return customRef((track, trigger) => {
|
|
return {
|
|
get() {
|
|
track();
|
|
return value;
|
|
},
|
|
set(newValue: T) {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
value = newValue;
|
|
trigger();
|
|
}, delay);
|
|
},
|
|
};
|
|
});
|
|
}
|