What is the purpose of the <Transition> component in Vue?
The <Transition> component helps animate elements when they enter or leave the DOM, making changes smooth and visually appealing.
Click to reveal answer
beginner
Name the three main CSS classes Vue automatically applies during a transition.
Vue applies v-enter-from, v-enter-active, and v-enter-to classes when an element enters, and similar classes for leaving like v-leave-from, v-leave-active, and v-leave-to.
Click to reveal answer
beginner
How do you trigger a transition on a conditional element in Vue?
Wrap the conditional element (like one controlled by v-if) inside a <Transition> component to animate its appearance and disappearance.
Click to reveal answer
intermediate
What role does the name attribute play in the <Transition> component?
The <code>name</code> attribute customizes the prefix for CSS classes Vue applies during transitions, allowing you to define your own class names for animations.
Click to reveal answer
intermediate
Can the <Transition> component animate multiple elements at once?
No, <Transition> works with a single element or component. To animate lists or multiple elements, use <TransitionGroup> instead.
Click to reveal answer
Which Vue component is used to animate an element entering or leaving the DOM?
A<Motion>
B<Transition>
C<Animate>
D<Effect>
✗ Incorrect
The component is designed to animate elements when they appear or disappear.
What CSS class does Vue apply at the start of an element entering transition?
Av-enter-active
Bv-leave-to
Cv-enter-from
Dv-leave-from
✗ Incorrect
The v-enter-from class is applied at the start of the entering transition to set initial styles.
How do you customize the CSS class names used by the <Transition> component?
AUse the name attribute
BUse the class attribute
CUse the id attribute
DUse inline styles
✗ Incorrect
The name attribute sets the prefix for transition CSS classes.
Which directive is commonly used with <Transition> to conditionally show an element?
Av-model
Bv-for
Cv-bind
Dv-if
✗ Incorrect
v-if controls whether an element is in the DOM, triggering transitions when wrapped in .
If you want to animate a list of items entering or leaving, which Vue component should you use?
A<TransitionGroup>
B<Transition>
C<AnimateList>
D<ListMotion>
✗ Incorrect
is designed for animating multiple elements like lists.
Explain how the component works in Vue and how it uses CSS classes to animate elements.
Think about how Vue changes classes to create smooth animations.
You got /4 concepts.
Describe how you would animate a button appearing and disappearing using Vue's component.
Consider the element's lifecycle and CSS class changes.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the <Transition> component in Vue?
easy
A. To handle form validation
B. To fetch data from an API
C. To animate elements when they appear or disappear
D. To create reusable components
Solution
Step 1: Understand the role of the Transition component
The Transition component is designed to wrap elements and animate their entrance and exit in the DOM.
Step 2: Compare with other options
Fetching data, form validation, and reusable components are unrelated to animation, which is the Transition's focus.
Final Answer:
To animate elements when they appear or disappear -> Option C
Hint: Transition = animation for showing/hiding elements [OK]
Common Mistakes:
Thinking Transition fetches data
Confusing Transition with form handling
Assuming Transition creates components
2. Which of the following is the correct way to use the <Transition> component with a CSS animation named "fade"?
easy
A. <Transition effect="fade"><div v-if="show">Hello</div></Transition>
B. <Transition animation="fade"><div v-if="show">Hello</div></Transition>
C. <Transition class="fade"><div v-if="show">Hello</div></Transition>
D. <Transition name="fade"><div v-if="show">Hello</div></Transition>
Solution
Step 1: Recall the correct attribute for CSS class prefix
The Transition component uses the name attribute to set the CSS class prefix for animations.
Step 2: Check the options for correct attribute usage
Only <Transition name="fade"><div v-if="show">Hello</div></Transition> uses name="fade", which is correct. Others use invalid attributes like animation, class, or effect.
Final Answer:
<Transition name="fade"><div v-if="show">Hello</div></Transition> -> Option D
Quick Check:
Use name="fade" for CSS animation prefix [OK]
Hint: Use name="animationName" for Transition CSS classes [OK]
Common Mistakes:
Using animation or effect instead of name
Adding class attribute to Transition
Forgetting to use v-if or v-show inside Transition
3. Given the code below, what will happen when show changes from true to false?
A. v-show should be replaced with v-if for Transition to work
B. The name attribute should be class instead
C. Transition does not work with v-show for enter/leave animations
D. The div must have a key attribute
Solution
Step 1: Understand difference between v-if and v-show with Transition
Transition works best with v-if because it controls element presence, triggering enter/leave animations.
Step 2: v-show only toggles visibility, so Transition cannot animate enter/leave properly
Using v-show inside Transition does not trigger the full animation lifecycle.
Final Answer:
v-show should be replaced with v-if for Transition to work -> Option A
Quick Check:
Use v-if, not v-show, inside Transition for animations [OK]
Hint: Use v-if, not v-show, inside Transition for animations [OK]
Common Mistakes:
Thinking v-show triggers enter/leave animations
Confusing name attribute with class
Believing key attribute is mandatory here
5. You want to animate a list of items appearing and disappearing using <Transition>. Which approach correctly applies the Transition component to animate each item individually when the list changes?
A) Wrap the entire list with one <Transition> component.
B) Wrap each list item inside its own <Transition> component.
C) Use <TransitionGroup> instead of <Transition> for lists.
D) Use <Transition> only on the parent container without keys on items.
hard
A. Wrap the entire list with one <Transition> component.
B. Use <TransitionGroup> instead of <Transition> for lists.
C. Wrap each list item inside its own <Transition> component.
D. Use <Transition> only on the parent container without keys on items.
Solution
Step 1: Recognize the need for list animations
Animating multiple items entering and leaving requires special handling to animate each item individually.
Step 2: Understand Vue's recommended component for list animations
<TransitionGroup> is designed to animate lists, handling keys and individual item transitions automatically.
Step 3: Evaluate other options
Wrapping entire list with one Transition animates the whole list as one block, not individual items. Wrapping each item manually is cumbersome. Using Transition without keys breaks animations.
Final Answer:
Use <TransitionGroup> instead of <Transition> for lists. -> Option B
Quick Check:
Use TransitionGroup for list animations [OK]
Hint: Use TransitionGroup for animating lists, not Transition [OK]
Common Mistakes:
Using Transition for entire list instead of TransitionGroup
Not adding keys to list items
Wrapping each item manually with Transition
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.