Consider a Vue 3 component that wraps an element with a <transition> tag and uses CSS classes for enter and leave animations. What is the visible behavior when the element is toggled?
<template> <transition name="fade"> <p v-if="show">Hello!</p> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) </script> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.5s ease; } .fade-enter-from, .fade-leave-to { opacity: 0; } .fade-enter-to, .fade-leave-from { opacity: 1; } </style>
Look at the CSS classes and their effects on opacity and transition properties.
The <transition> component applies CSS classes during enter and leave phases. The classes fade-enter-active and fade-leave-active define a transition on opacity. The fade-enter-from and fade-leave-to classes set opacity to 0, and fade-enter-to and fade-leave-from set opacity to 1. This causes a smooth fade effect.
Vue transition classes follow a naming pattern based on the transition name. If the transition name is slide, which CSS class targets the enter active state?
Vue uses a fixed naming pattern for transition classes.
The correct class for the enter active state is name-enter-active. For a transition named slide, it is .slide-enter-active.
This Vue component uses a <transition> with CSS classes, but the element appears and disappears instantly without animation. What is the likely cause?
<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 1s ease; } .fade-enter-from, .fade-leave-to { opacity: 0; } .fade-enter-to, .fade-leave-from { opacity: 1; } </style>
Check the official Vue 3 transition class naming conventions.
Vue 3 uses the classes fade-enter-from and fade-leave-from to define the starting states of the transition. Using fade-enter and fade-leave is from Vue 2 and will not trigger animations in Vue 3.
Given this Vue transition with CSS classes, what is the opacity of the element after the enter transition finishes?
<template> <transition name="fade"> <span v-if="show">Text</span> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) </script> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.3s ease-in-out; } .fade-enter-from, .fade-leave-to { opacity: 0; } .fade-enter-to, .fade-leave-from { opacity: 1; } </style>
Look at the fade-enter-to class opacity value.
After the enter transition finishes, the element has the fade-enter-to class which sets opacity to 1, making it fully visible.
In Vue 3's CSS transition system, which class is applied to the element at the start of the leave phase to define its initial style?
Think about the naming pattern for the leave phase start state.
The class name-leave-from is applied at the start of the leave phase to set the initial style before the transition runs.