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