fix: toRefs

pull/30/MERGE
xingyu 2023-08-11 20:18:23 +08:00
parent 2c9f11bce3
commit d024950dda
1 changed files with 4 additions and 8 deletions

View File

@ -1,20 +1,16 @@
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { onBeforeUpdate, ref } from 'vue' import { onBeforeUpdate, ref } from 'vue'
function useRefs<T = HTMLElement>(): { refs: Ref<T[]>; setRefs: (index: number) => (el: T) => void } { export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
const refs = ref([]) as Ref<T[]> const refs = ref([]) as Ref<HTMLElement[]>
onBeforeUpdate(() => { onBeforeUpdate(() => {
refs.value = [] refs.value = []
}) })
const setRefs = (index: number) => (el: T) => { const setRefs = (index: number) => (el: HTMLElement) => {
refs.value[index] = el refs.value[index] = el
} }
return { return [refs, setRefs]
refs,
setRefs,
}
} }
export { useRefs }