mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 18:53:01 +08:00
perf: useRefs函数接收泛型类型 (#2952)
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { onBeforeUpdate, shallowRef } from 'vue';
|
import { onBeforeUpdate, shallowRef } from 'vue';
|
||||||
|
|
||||||
function useRefs(): {
|
function useRefs<T = HTMLElement>(): {
|
||||||
refs: Ref<HTMLElement[]>;
|
refs: Ref<T[]>;
|
||||||
setRefs: (index: number) => (el: HTMLElement) => void;
|
setRefs: (index: number) => (el: T) => void;
|
||||||
} {
|
} {
|
||||||
const refs = shallowRef([]) as Ref<HTMLElement[]>;
|
const refs = shallowRef([]) as Ref<T[]>;
|
||||||
|
|
||||||
onBeforeUpdate(() => {
|
onBeforeUpdate(() => {
|
||||||
refs.value = [];
|
refs.value = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
const setRefs = (index: number) => (el: HTMLElement) => {
|
const setRefs = (index: number) => (el: T) => {
|
||||||
refs.value[index] = el;
|
refs.value[index] = el;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user