Which of the following best explains why adding transitions to Vue components improves user experience?
Think about how visual changes affect how comfortable and clear the app feels to users.
Transitions create smooth visual changes that guide the user's attention and make the interface feel more natural and less jarring.
Given a Vue component wrapped in a <transition> tag, what is the visible effect when the component appears or disappears?
<template> <transition name="fade"> <p v-if="show">Hello!</p> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) </script>
Consider what the fade transition name implies about the animation.
The <transition> with name 'fade' applies CSS classes that create a fade effect on enter and leave.
Which option correctly uses Vue's <transition> component to apply a fade effect with a 0.5s duration?
Remember that Vue transition duration is controlled by CSS, not by a duration attribute.
Vue's <transition> uses CSS classes for timing. The appear attribute triggers animation on initial render. Duration is set in CSS.
Given this Vue code, why does the transition not animate when toggling show?
<template>
<transition name="slide">
<div v-if="show">Content</div>
</transition>
</template>
<script setup>
import { ref } from 'vue'
const show = ref(false)
</script>
<style>
.slide-enter-active, .slide-leave-active {
transition: transform 0.3s ease;
}
.slide-enter-from, .slide-leave-to {
transform: translateX(100%);
}
.slide-enter-to, .slide-leave-from {
transform: translateX(0);
}
</style>Think about when the element is first rendered and how that affects animation.
Since show starts as false, the element is not in the DOM initially, so no enter animation runs on page load.
Consider this Vue component using transition hooks to log and modify state:
<template>
<transition
@before-enter="beforeEnter"
@enter="enter"
@after-enter="afterEnter"
>
<div v-if="visible">Box</div>
</transition>
<button @click="toggle">Toggle</button>
</template>
<script setup>
import { ref } from 'vue'
const visible = ref(false)
function beforeEnter(el) {
el.style.opacity = 0
}
function enter(el, done) {
el.style.transition = 'opacity 0.3s'
el.style.opacity = 1
setTimeout(done, 300)
}
function afterEnter(el) {
console.log('Entered')
}
function toggle() {
visible.value = !visible.value
}
</script>After clicking the toggle button once, what is the visible opacity of the box?
Consider how the transition hooks change opacity and when the done callback is called.
The enter hook sets opacity to 1 and calls done after 300ms, so the box becomes fully visible.