mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 08:36:19 +08:00
feat: 重构 useRefs
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from './onMountedOrActivated';
|
||||
export * from './useAttrs';
|
||||
export * from './useRefs';
|
||||
|
16
packages/hooks/src/useRefs.ts
Normal file
16
packages/hooks/src/useRefs.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { Ref } from 'vue';
|
||||
import { ref, onBeforeUpdate } from 'vue';
|
||||
|
||||
export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
|
||||
const refs = ref([]) as Ref<HTMLElement[]>;
|
||||
|
||||
onBeforeUpdate(() => {
|
||||
refs.value = [];
|
||||
});
|
||||
|
||||
const setRefs = (index: number) => (el: HTMLElement) => {
|
||||
refs.value[index] = el;
|
||||
};
|
||||
|
||||
return [refs, setRefs];
|
||||
}
|
Reference in New Issue
Block a user