Skip to content

useTemplateRefsList

将 ref 绑定到 v-for 内的模板元素和组件的简写。

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

示例

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>