useRefs
Commons
stable
Manages a dynamic array of template refs that is reset before each update cycle. Provides an updateRef(el, i) callback designed for use with :ref in v-for loops, where Vue replaces individual refs by index. The refs array is always fresh (cleared in onBeforeUpdate) so stale elements from a previous render do not leak.
API
Signature
Full TypeScript signature sourced from the composable file.
API
Return values
Properties and methods exposed by the composable return object.
- refs
- Array of collected template refs. Each slot corresponds to the index passed to updateRef. Cleared before every update cycle to avoid stale entries.
- updateRef
- Assign to :ref in a v-for loop: :ref="(el) => updateRef(el, index)". Sets refs.value[i] = el on mount and leaves the slot undefined on unmount.
Usage
Examples
Ready-to-paste usage snippets.
Collect refs from a v-for list
Refs of child Origam components