fix: toRefs
parent
2c9f11bce3
commit
d024950dda
|
@ -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 }
|
|
||||||
|
|
Loading…
Reference in New Issue