Template Refs inside v-for not working with Composition API
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.14.0
- Nuxt Version:
3.0.0-27484505.9f6eff7
- Package Manager:
npm@8.3.1
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
Sharing the SFC code.
<template>
<div>
<div v-for="i in 3" :key="i" class="content" ref="contentRef">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</div>
</div>
</template>
<script setup>
const contentRef = ref([]);
onMounted(() => {
console.log("On Mounted Ref:");
console.log(JSON.stringify(contentRef.value.map((cr) => cr)));
});
</script>
<style scoped>
.content {
display: table;
padding: 30px;
height: 60px;
border-bottom: 1px solid grey;
}
</style>
Describe the bug
I am trying to use Template Refs inside v-for loop. But the corresponding reference returns an empty array.
The same example runs correctly on Vue SFC Playground.
Additional context
No response
Logs
On Mounted Ref:
[]
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
can't use template ref on component in vue 3 composition api
I ran into this issue today. The problem is that, when using the <script setup> pattern, none of the declared variables are returned....
Read more >How to use $refs in Vue 3 with Composition API and Script ...
First, you would declare a variable, initializing it to null, then you need to assign that variable name as a “ref” attribute on...
Read more >The Beginners Guide to Template Refs - LearnVue
In this tutorial, we'll be learning all about template refs: how to use them in both the Options API and Composition API, some...
Read more >Template Refs - Vue.js
ref is a special attribute, similar to the key attribute discussed in the v-for chapter. It allows us to obtain a direct reference...
Read more >Vue 3 Composition API: How to Omit `.value` in refs
In this article, we discuss how to omit in VueJS refs, creating APIs ... For this to work, you will need to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danielroe latest
Vue
probably fixed this: https://github.com/vuejs/core/blob/main/CHANGELOG.md#3232-2022-04-12This is a Vue SSR bug: see reproduction without Nuxt.
You can track at https://github.com/vuejs/core/issues/5525.
See also https://github.com/nuxt/framework/discussions/3661.