key attribute inside a TransitionGroup list?Consider a Vue 3 component using <TransitionGroup> to animate a list of items. Each item has a unique key attribute. What is the visible effect if you remove the key attribute from the list items?
<template> <TransitionGroup name="fade" tag="ul"> <li v-for="item in items" :key="item.id">{{ item.text }}</li> </TransitionGroup> </template>
Think about how Vue tracks list items for transitions.
Vue requires a unique key on each item inside a TransitionGroup to track elements for proper animation. Without keys, Vue cannot identify which items changed, causing warnings and broken animations.
TransitionGroup with a custom tag and CSS classes?Choose the correct Vue 3 syntax to wrap a list with TransitionGroup using a div tag and applying the CSS class list-container.
Remember how to bind static classes in Vue templates.
Static classes are added with the class attribute directly. Using :class expects a JavaScript expression. Option C correctly uses class="list-container" for a static class.
TransitionGroup?Given this Vue 3 component code, what is the final list rendered after clicking the 'Remove' button once?
<template> <TransitionGroup tag="ul" name="fade"> <li v-for="item in items" :key="item.id">{{ item.text }}</li> </TransitionGroup> <button @click="removeFirst">Remove</button> </template> <script setup> import { ref } from 'vue' const items = ref([ { id: 1, text: 'Apple' }, { id: 2, text: 'Banana' }, { id: 3, text: 'Cherry' } ]) function removeFirst() { items.value.shift() } </script>
What does shift() do to an array?
The shift() method removes the first element from the array. So 'Apple' is removed, leaving 'Banana' and 'Cherry'. The TransitionGroup animates this change.
TransitionGroup animation not run on list reorder?In this Vue 3 code, the list items reorder but no animation runs. What is the cause?
<template> <TransitionGroup name="slide" tag="ul"> <li v-for="item in items" :key="item.text">{{ item.text }}</li> </TransitionGroup> <button @click="reverse">Reverse</button> </template> <script setup> import { ref } from 'vue' const items = ref(['One', 'Two', 'Three']) function reverse() { items.value = [...items.value].reverse() } </script>
Keys must uniquely identify items even after reorder.
Using the item text as key can cause Vue to confuse elements if texts are not unique or stable. This prevents proper animation on reorder. Unique stable keys like IDs are recommended.
TransitionGroup differ from Transition in Vue 3?Choose the best explanation of the difference between TransitionGroup and Transition components in Vue 3.
Think about single vs multiple elements animation.
Transition is designed to animate one element or component entering or leaving. TransitionGroup handles lists of elements, including move animations when items reorder.