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 { onBeforeUpdate, ref } from 'vue'
function useRefs<T = HTMLElement>(): { refs: Ref<T[]>; setRefs: (index: number) => (el: T) => void } {
const refs = ref([]) as Ref<T[]>
export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
const refs = ref([]) as Ref<HTMLElement[]>
onBeforeUpdate(() => {
refs.value = []
})
const setRefs = (index: number) => (el: T) => {
const setRefs = (index: number) => (el: HTMLElement) => {
refs.value[index] = el
}
return {
refs,
setRefs,
}
return [refs, setRefs]
}
export { useRefs }