D
D
Darkness2019-11-20 08:57:14
Vue.js
Darkness, 2019-11-20 08:57:14

What's wrong with transition-group or why "children must be keyed"?

I can't figure out why transition-group doesn't want to work here?

<transition-group name="collapse">
    <div class="customers">
        <SimpleCustomer v-if="!collapse" :customer="contact.last_deal_with" />
        <div class="customers--list" v-else>
           <SimpleCustomer :customer="membership.customer" :contact="contact.id" :person-post="membership.post" :collapse="collapse" :edit="edit" v-for="(membership, i) in memberships" :key="membership.customer.id"/>
        </div>
        <CreateMembership @addNewCustomer="addNewCustomer" :memberships="memberships" v-show="edit" :contact="contact"/>
      </div>
    </transition-group>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WinPooh32, 2019-11-20
@WinPooh32

When Vue is updating a list of elements rendered with v-for, by default it uses an “in-place patch” strategy. If the order of the data items has changed, instead of moving the DOM elements to match the order of the items, Vue will patch each element in-place and make sure it reflects what should be rendered at that particular index. This is similar to the behavior of track-by="$index" in Vue 1.x.

https://vuejs.org/v2/guide/list.html
thats why you should have use :key="item"
source:
https://stackoverflow.com/questions/53194769/vuejs...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question