0
0
Vueframework~20 mins

Dynamic transitions in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic Transitions 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 name changes dynamically?

Consider a Vue 3 component that toggles between two transition names based on a button click. What will be the visible effect on the element's animation when the transition name changes?

Vue
<template>
  <button @click="toggle">Toggle Transition</button>
  <transition :name="transitionName">
    <p v-if="show">Hello Vue!</p>
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
const transitionName = ref('fade')
function toggle() {
  show.value = !show.value
  transitionName.value = transitionName.value === 'fade' ? 'slide' : 'fade'
}
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.slide-enter-active, .slide-leave-active {
  transition: transform 0.5s;
}
.slide-enter-from {
  transform: translateX(-100%);
}
.slide-leave-to {
  transform: translateX(100%);
}
</style>
AThe element will not animate at all because dynamic transition names are not supported in Vue.
BThe element will always use the initial transition name and ignore changes to the transitionName variable.
CThe element will animate with the current transition name each time it appears or disappears, switching between fade and slide animations.
DThe element will animate with both fade and slide transitions simultaneously, causing a mixed effect.
Attempts:
2 left
💡 Hint

Think about how Vue applies transition classes based on the name attribute binding.

📝 Syntax
intermediate
1:30remaining
Which option correctly binds a dynamic transition name in Vue 3?

Given a Vue 3 template, which syntax correctly binds a dynamic transition name stored in a variable currentTransition?

Vue
<template>
  <transition ???>
    <div v-if="visible">Content</div>
  </transition>
</template>
A:name="currentTransition"
Bname="{{ currentTransition }}"
Cv-bind:name="currentTransition"
Dname="currentTransition"
Attempts:
2 left
💡 Hint

Remember how to bind props dynamically in Vue templates.

🔧 Debug
advanced
2:30remaining
Why does the transition not animate when toggling visibility?

Given this Vue 3 component, the element appears and disappears instantly without animation. What is the cause?

Vue
<template>
  <transition name="fade">
    <p v-show="visible">Fade me</p>
  </transition>
  <button @click="visible = !visible">Toggle</button>
</template>

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

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
</style>
AThe transition name 'fade' is not defined in the CSS, so no animation occurs.
BThe button click does not update the visible variable correctly, so no animation triggers.
CUsing v-show instead of v-if prevents the transition from triggering enter and leave animations.
DThe transition component must wrap a single root element, but <p> is not allowed.
Attempts:
2 left
💡 Hint

Check how refs are updated from template event handlers in Vue 3 <script setup>.

state_output
advanced
2:00remaining
What is the final class list on the element after transition enter finishes?

In Vue 3, when a transition with name 'slide' finishes entering, which classes remain on the element?

Vue
<style>
.slide-enter-active { transition: transform 0.3s; }
.slide-enter-from { transform: translateX(-100%); }
.slide-enter-to { transform: translateX(0); }
</style>

<template>
  <transition name="slide">
    <div v-if="show">Slide me</div>
  </transition>
</template>

<script setup>
import { ref, onMounted } from 'vue'
const show = ref(false)
onMounted(() => { show.value = true })
</script>
ANo transition classes remain after enter finishes
Bslide-enter-active and slide-enter-to
Cslide-enter-from only
Dslide-enter-active only
Attempts:
2 left
💡 Hint

Recall the sequence of classes Vue applies during enter transitions.

🧠 Conceptual
expert
3:00remaining
How does Vue 3 handle dynamic transition components with multiple nested transitions?

In a Vue 3 app, you have nested <transition> components with dynamic names that change based on user interaction. What is the key behavior Vue uses to manage these nested dynamic transitions correctly?

AVue requires manual event listeners to synchronize nested transitions when using dynamic names.
BVue merges all nested transitions into a single transition using the outermost transition name, ignoring inner dynamic names.
CVue only applies transitions to the outermost component and disables inner nested transitions to avoid conflicts.
DVue tracks each transition instance separately and applies the correct CSS classes based on the current dynamic name for each nested transition.
Attempts:
2 left
💡 Hint

Think about how Vue manages multiple transition components in the virtual DOM.