-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
'Duplicate keys detected: ...' error with same keyed children inside a v-fored template #7323
Comments
Unfortunately, this is expected, both elements being at the same level (under |
Thanks for the quick reply 👏 It makes perfectly sense (now that I know |
Contributions to docs are always welcome but I think invisible wrapper is accurate and if you try to use |
@posva Thx to Reply. It is a hard to find mistake |
Borrowing from the solution here Duplicate keys detected: { key }. This may cause an update error, You can include the index as part of your v-for directive and then make a composite key including that: <div v-for="(item, i) in items"
:key="`${i}-${item.id}`"></div> |
Hello, this is the solution I found while finding a better way, or the core of vue solves it:
The key must unique, therefore in larger arrangements a more complex mathematical operation can be done and thus prevent the keys from duplicating. |
Using a number could be problematic and still show collisions, using a string as the comment above shows is the most secure way. I'm locking this issue as it was resolved and solutions are still very visible :) |
Version
2.5.13
Reproduction link
https://jsfiddle.net/56zfwbe5/1/
Steps to reproduce
What is expected?
Children inside a repeated
<template>
should share the same keys as they should both re-render if the target element changes.What is actually happening?
Errors are raised with the message : [Vue warn]: Duplicate keys detected is raised.
Cause
This behavior is linked to this PR and was also references in this issue
Workaround
You could avoid this error by adding some prefix / suffix
The text was updated successfully, but these errors were encountered: