You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
439 B
19 lines
439 B
import type { Ref } from 'vue';
|
|
import { shallowRef, watchEffect } from 'vue';
|
|
|
|
export default function useDebounce<T>(value: Ref<T[]>): Ref<T[]> {
|
|
const cacheValue = shallowRef(value.value.slice());
|
|
let timeout: any = null;
|
|
watchEffect(() => {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(
|
|
() => {
|
|
cacheValue.value = value.value;
|
|
},
|
|
value.value.length ? 0 : 10,
|
|
);
|
|
});
|
|
|
|
return cacheValue;
|
|
}
|