0
0
Vueframework~20 mins

Enter and leave transitions in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when the <Transition> component wraps a conditionally rendered element?

Consider this Vue 3 code snippet using the <Transition> component:

<template>
  <Transition name="fade">
    <div v-if="show">Hello</div>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>

What is the visible behavior when show changes from true to false?

Vue
<template>
  <Transition name="fade">
    <div v-if="show">Hello</div>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>
AThe <div> disappears immediately without any animation.
BThe <div> remains visible even if <code>show</code> is false.
CThe <div> fades in when shown but disappears immediately when hidden.
DThe <div> fades out smoothly before being removed from the DOM.
Attempts:
2 left
💡 Hint

Think about what the <Transition> component does with elements entering and leaving the DOM.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a CSS fade transition for Vue's <Transition> component?

You want to create a fade effect for entering and leaving elements using Vue's <Transition> with name="fade". Which CSS snippet is correct?

A.fade-enter-active, .fade-leave-active { transition: opacity 0.5s; } .fade-enter-from, .fade-leave-to { opacity: 0; } .fade-enter-to, .fade-leave-from { opacity: 1; }
B.fade-enter, .fade-leave { transition: opacity 0.5s; } .fade-enter-active, .fade-leave-active { opacity: 0; }
C.fade-enter-active { opacity: 1; } .fade-leave-active { opacity: 0; transition: opacity 0.5s; }
D.fade-enter-from, .fade-leave-from { transition: opacity 0.5s; } .fade-enter-to, .fade-leave-to { opacity: 1; }
Attempts:
2 left
💡 Hint

Remember Vue uses -enter-active and -leave-active classes for transitions and -from/-to for start/end states.

state_output
advanced
2:00remaining
What is the final DOM state after toggling a <Transition> wrapped element off?

Given this Vue 3 component:

<template>
  <button @click="show = !show">Toggle</button>
  <Transition name="slide">
    <p v-if="show">Slide me</p>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>

After clicking the button to set show to false, what happens to the <p> element in the DOM?

Vue
<template>
  <button @click="show = !show">Toggle</button>
  <Transition name="slide">
    <p v-if="show">Slide me</p>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>
AThe <p> element animates sliding out and then is removed from the DOM.
BThe <p> element is immediately removed from the DOM with no animation.
CThe <p> element remains in the DOM but is hidden with CSS.
DThe <p> element stays visible and does not respond to the toggle.
Attempts:
2 left
💡 Hint

Think about how Vue handles leave transitions with <Transition>.

🔧 Debug
advanced
2:00remaining
Why does this Vue transition not animate on leave?

Look at this Vue 3 code:

<template>
  <Transition name="fade">
    <div v-if="visible">Content</div>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const visible = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s ease;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to {
  opacity: 1;
}
</style>

When visible changes from true to false, the element disappears immediately without fading out. Why?

Vue
<template>
  <Transition name="fade">
    <div v-if="visible">Content</div>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const visible = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s ease;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to {
  opacity: 1;
}
</style>
AThe transition duration is too short to notice the animation.
BThe <code>v-if</code> directive is not reactive, so the transition does not trigger.
CThe CSS is missing the .fade-leave-from class, so leave animation cannot start properly.
DThe transition name 'fade' is not correctly applied to the element.
Attempts:
2 left
💡 Hint

Check if all required CSS classes for enter and leave states are defined.

🧠 Conceptual
expert
3:00remaining
How does Vue's <Transition> component manage multiple elements leaving simultaneously?

When multiple elements inside a <TransitionGroup> leave at the same time, how does Vue ensure smooth animations?

AVue removes all elements immediately and applies a global fade-out animation to the container.
BVue delays removing each element until its individual leave animation finishes, tracking each separately.
CVue queues the leave animations to run one after another, never overlapping.
DVue clones the elements and animates the clones while removing the originals instantly.
Attempts:
2 left
💡 Hint

Think about how Vue handles asynchronous animations for multiple elements.