Skip to content

useTemplateRefsList

Category
Export Size
133 B
Last Changed
3 months ago

Shorthand for binding refs to template elements and components inside v-for.

Demo

12345
Open the console to see the output

Usage

vue
<script setup lang="ts">
import { 
useTemplateRefsList
} from '@vueuse/core'
import {
onUpdated
} from 'vue'
const
refs
=
useTemplateRefsList
<HTMLDivElement>()
onUpdated
(() => {
console
.
log
(
refs
)
}) </script> <template> <
div
v-for="
i
of 5"
:key
="
i
"
:ref
="
refs
.
set
" />
</template>

Type Declarations

ts
export type 
TemplateRefsList
<
T
> =
T
[] & {
set
: (
el
: object | null) => void
} export declare function
useTemplateRefsList
<
T
= Element>():
Readonly
<
Ref
<
Readonly
<
TemplateRefsList
<
T
>>>
>

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
SerKo
David Gonzalez
bjym

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.8.0 on
a086e - fix: stricter types

Released under the MIT License.

FREE WEEKEND
Unlimited access to ALL Vue School courses
8-9 November 2025
Reserve Your Spot
8-9 November 2025