mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-embeded.git
synced 2025-06-25 05:54:15 +08:00
25 lines
542 B
TypeScript
25 lines
542 B
TypeScript
import type { ComponentPublicInstance, Ref } from 'vue';
|
|
import { onBeforeUpdate, shallowRef } from 'vue';
|
|
|
|
function useRefs<T = HTMLElement>(): {
|
|
refs: Ref<T[]>;
|
|
setRefs: (index: number) => (el: Element | ComponentPublicInstance | null) => void;
|
|
} {
|
|
const refs = shallowRef([]) as Ref<T[]>;
|
|
|
|
onBeforeUpdate(() => {
|
|
refs.value = [];
|
|
});
|
|
|
|
const setRefs = (index: number) => (el: Element | ComponentPublicInstance | null) => {
|
|
refs.value[index] = el as T;
|
|
};
|
|
|
|
return {
|
|
refs,
|
|
setRefs,
|
|
};
|
|
}
|
|
|
|
export { useRefs };
|