0
0
Vueframework~8 mins

Transition component basics in Vue - Performance & Optimization

Choose your learning style9 modes available
Performance: Transition component basics
MEDIUM IMPACT
This affects the smoothness and speed of visual changes on the page, impacting user interaction responsiveness and visual stability.
Animating element appearance and disappearance
Vue
<template>
  <Transition name="fade">
    <div v-if="show">Content</div>
  </Transition>
</template>

<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>
Vue's Transition component batches DOM updates and applies CSS classes at the right time, reducing layout thrashing.
📈 Performance GainSingle reflow per transition cycle, smoother animations, better input responsiveness.
Animating element appearance and disappearance
Vue
<template>
  <div v-if="show" class="fade">Content</div>
</template>

<style>
.fade {
  transition: opacity 0.5s ease;
  opacity: 1;
}
.fade-leave-active {
  opacity: 0;
}
</style>
Directly toggling classes without Vue's Transition component causes abrupt DOM changes and multiple reflows.
📉 Performance CostTriggers multiple reflows and repaints per toggle, causing jank during interaction.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Direct class toggle without TransitionMultiple add/remove nodesMultiple reflows per toggleHigh paint cost due to layout thrashing[X] Bad
Vue Transition component with opacity animationMinimal DOM changesSingle reflow per animationLow paint cost with GPU compositing[OK] Good
Rendering Pipeline
The Transition component manages CSS class changes to trigger animations, affecting style calculation and paint stages without forcing layout recalculations.
Style Calculation
Paint
Composite
⚠️ BottleneckPaint stage due to opacity changes triggering repaints
Core Web Vital Affected
INP
This affects the smoothness and speed of visual changes on the page, impacting user interaction responsiveness and visual stability.
Optimization Tips
1Use Vue's Transition component to batch DOM updates during animations.
2Animate opacity or transform properties to minimize layout recalculations.
3Avoid toggling classes directly on elements without Transition for smoother performance.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using Vue's Transition component for animations?
AIt disables CSS transitions to speed up rendering.
BIt increases the number of DOM nodes for smoother animations.
CIt batches DOM updates to reduce layout thrashing and repaints.
DIt forces synchronous JavaScript execution during animations.
DevTools: Performance
How to check: Record a performance profile while toggling the transition. Look for layout thrashing and paint events in the flame chart.
What to look for: Smooth frame times with minimal layout recalculations and paint events indicate good transition performance.