Skip to content

useTemplateRefsList

Category
Export Size
177 B
Last Changed
last year

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

WARNING

This function only works for Vue 3

Demo

12345
Open the console to see the output

Usage

vue
<script setup lang="ts">
import { onUpdated } from 'vue'
import { useTemplateRefsList } from '@vueuse/core'

const refs = useTemplateRefsList<HTMLDivElement>()

onUpdated(() => {
  console.log(refs)
})
</script>

<template>
  <div v-for="i of 5" :key="i" :ref="refs.set" />
</template>

Type Declarations

typescript
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
bjym

Changelog

v10.8.0 on 2/20/2024
a086e - fix: stricter types

Released under the MIT License.

Build smarter with AI
Become an AIDD Insider
Secure early access + the best pricing & perks we'll ever offer. 24H only
Get notified
02
days
:
05
hours
:
14
minutes
:
12
seconds
: