vue-vben-admin/packages/hooks/src/useRefs.ts

17 lines
394 B
TypeScript
Raw Normal View History

2021-08-13 00:12:51 +08:00
import type { Ref } from 'vue';
2023-04-06 23:28:37 +08:00
import { onBeforeUpdate, ref } from 'vue';
2020-11-18 22:41:59 +08:00
2020-12-10 23:58:11 +08:00
export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
2021-08-13 00:12:51 +08:00
const refs = ref([]) as Ref<HTMLElement[]>;
2020-11-18 22:41:59 +08:00
onBeforeUpdate(() => {
refs.value = [];
});
2020-12-10 23:58:11 +08:00
const setRefs = (index: number) => (el: HTMLElement) => {
2020-11-18 22:41:59 +08:00
refs.value[index] = el;
};
return [refs, setRefs];
}