15 lines
356 B
TypeScript
15 lines
356 B
TypeScript
import { onBeforeUpdate, ref, Ref } from 'vue';
|
|
|
|
export type UseRef = [(el: any, key: string | number) => void, Ref<any>];
|
|
|
|
export const useRef = (): UseRef => {
|
|
const refs = ref<any>({});
|
|
const setRef = (el: any, key: string | number) => {
|
|
refs.value[key] = el;
|
|
};
|
|
onBeforeUpdate(() => {
|
|
refs.value = {};
|
|
});
|
|
return [setRef, refs];
|
|
};
|