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.
<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>
<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>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct class toggle without Transition | Multiple add/remove nodes | Multiple reflows per toggle | High paint cost due to layout thrashing | [X] Bad |
| Vue Transition component with opacity animation | Minimal DOM changes | Single reflow per animation | Low paint cost with GPU compositing | [OK] Good |