mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types: improve useRefs typing (#8117)
This commit is contained in:
parent
980ab18076
commit
38e3bc948d
@ -1,15 +1,15 @@
|
||||
import { ref, onBeforeUpdate } from 'vue';
|
||||
import { ref, Ref, onBeforeUpdate } from 'vue';
|
||||
|
||||
export function useRefs() {
|
||||
const refs = ref([] as Element[]);
|
||||
export function useRefs<T = Element>() {
|
||||
const refs = ref([]) as Ref<T[]>;
|
||||
|
||||
onBeforeUpdate(() => {
|
||||
refs.value = [];
|
||||
});
|
||||
|
||||
const setRefs = (index: number) => (el: Element) => {
|
||||
refs.value[index] = el;
|
||||
const setRefs = (index: number) => (el: unknown) => {
|
||||
refs.value[index] = el as T;
|
||||
};
|
||||
|
||||
return [refs, setRefs];
|
||||
return [refs, setRefs] as const;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user