Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Refs inside v-for not working with Composition API #13621

Closed
dikesh opened this issue Apr 5, 2022 · 5 comments
Closed

Template Refs inside v-for not working with Composition API #13621

dikesh opened this issue Apr 5, 2022 · 5 comments

Comments

@dikesh
Copy link

dikesh commented Apr 5, 2022

Environment

  • 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:
[]
@danielroe
Copy link
Member

This is a Vue SSR bug: see reproduction without Nuxt.

You can track at vuejs/core#5525.

See also https://github.com/nuxt/framework/discussions/3661.

@oritwoen
Copy link
Contributor

@danielroe latest Vue probably fixed this: https://github.com/vuejs/core/blob/main/CHANGELOG.md#3232-2022-04-12

@danielroe
Copy link
Member

Any chance you could test with latest vue to see?

@oritwoen
Copy link
Contributor

Updated reproduction in StackBlitz: https://stackblitz.com/edit/github-6ovsn2-9srfej

I also check latest Nuxt after nuxt/framework#3968 and also works! 🎉 🥳

A little note. Using JSON.stringify on reproduction returns empty objects instead of DOM tree elements.

Before 3.2.32:
Zrzut ekranu z 2022-04-12 12-46-03

With 3.3.32:

Zrzut ekranu z 2022-04-12 12-47-39

@dikesh
Copy link
Author

dikesh commented Apr 13, 2022

It is working as expected now with vue@3.2.32.

@dikesh dikesh closed this as completed Apr 13, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants