1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| 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 };
|
|