Trying to use <animation-group>
in my component template, but getting error:
[Vue warn]: <transition-group> children must be keyed: <div>
But I'm pretty sure that they are keyed.
//js
Vue.component('instruments', {
template: `
<transition-group name="fade">
<div class="instruments">
<div class="instrument" v-for="(instrument, index) in filteredInstruments" v-bind:key="index">
<img v-bind:src="instrument.photo">
<span class="name">{{ instrument.name }}</span>
<span class="construction">{{ instrument.top }} / {{ instrument.backAndSides }}</span>
<span class="price">$ {{ instrument.price }}</span>
</div>
</div>
</transition-group>
`
}
I think that setting v-bind:key="index"
would take satisfy this, but I get the error pasted above.
You have to give a unique key to your
<div class="instruments">
element since elements inside a<transition-group>
, specifically the immediate children, are always required to have a unique key attribute.
If you don't want to give a key to .instruments
, you can remove that element and assign a tag
and class
attributes to <transition-group>
instead since it renders an actual element which by default is a <span>
.
<transition-group name="fade" tag="div" class="instruments">
In this way, the warning would not appear anymore since the immediate children (.instrument
) have their unique keys assigned to them.
In some common cases.
You should check to see if there are any elements remain except all elements in for loop.
You may have an incorrect structure like this:
<transition-group name="fade">
<div v-for="item in listItem" :key="item.id">
</div>
<n-button>Load more...</n-button>
</transition-group>
n-button is the cause. Should move n-button out side transition-group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With