Currently, I have a display of lists of items through the use of v-for
. Initially, only the summary section of each item is visible. Upon clicking on an item, the details section is supposed to appear.
This functionality is achieved by adding or removing an active
class and toggling between display: block
and display: none
for the details part of the item.
My goal now is to incorporate smooth transitions into this process. I followed the example provided in the Vue.js documentation, specifically the first example. However, despite my efforts, the transition does not seem to work as intended. Currently, when clicking on the item, the details section instantly appears and disappears without any transition effects taking place.
I am struggling to understand what could be wrong with my code. Here is the snippet:
.event-details {
display: none;
}
.event.active .event-details-enter-active,
.event.active .event-details-leave-active {
transition: opacity .5s;
transition: height .5s;
}
.event.active .event-details-enter,
.event.active .event-details-leave-to {
opacity: 0;
display: none;
height: 0;
}
.event.active .event-details-enter,
.event.active .event-details-leave-to {
opacity: 1;
display: block;
height: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<li :class="{ active: event.active }" v-for="event in events" @click="showEvent(event)">
<div class="event-summary">
content
</div>
<transition name="event-details">
<div class="event-details">
content
</div>
</transition>
</li>
Additionally, here is a console.log
of the events array for reference: