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

v-for on template, must have key, but cannot have key #1977

Closed
Beiri22 opened this issue Aug 26, 2020 · 2 comments
Closed

v-for on template, must have key, but cannot have key #1977

Beiri22 opened this issue Aug 26, 2020 · 2 comments

Comments

@Beiri22
Copy link

Beiri22 commented Aug 26, 2020

Version

3.0.0-rc.8

Reproduction link

https://gitlab.com/Beiri22Ny/vue-min-exp

Steps to reproduce

Populate 3 rows per data entry in a table via v-for.

did not work, because it breaks the table. But I found some hint about the pseudo-element . So I tried:
<table>
  <template v-for="entry in old" :key="entry.name">
    <tr>...</tr>
    <tr>...</tr>
    <tr>...</tr>
  </template>
</table>

4:3 error '' cannot be keyed. Place the key on real elements instead vue/no-template-key
5:5 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key
6:5 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key
7:5 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key

So, then put the key on the elements. Tried with 3x the same key; and with different ones.

<table>
  <template v-for="entry in old">
    <tr :key="entry.name" >...</tr>
    <tr :key="entry.name" >...</tr>
    <tr :key="entry.name" >...</tr>
  </template>
</table>

VueCompilerError: key should be placed on the tag.

Following the compiler-given advice seems to me like entering an infinite loop

What is expected?

3 rows per entry in the table, no error messages.

What is actually happening?

see above.


I'm not sure, if it's just a lint-thing...

@jacekkarczmarczyk
Copy link
Contributor

@yyx990803
Copy link
Member

Wait for the next release of the eslint plugin. You can disable the lint rule for now.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants