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.
24 lines
542 B
24 lines
542 B
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 };
|
|
|