Performance: Enter and leave transitions
This affects the smoothness and speed of element appearance and disappearance on the page, impacting user interaction responsiveness and visual stability.
<template> <transition name="fade"> <div v-if="show" class="box">Content</div> </transition> </template> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.5s ease; will-change: opacity; } .fade-enter, .fade-leave-to { opacity: 0; } </style>
<template> <transition name="fade"> <div v-if="show" class="box">Content</div> </transition> </template> <style> .fade-enter-active, .fade-leave-active { transition: all 0.5s ease; } .fade-enter, .fade-leave-to { opacity: 0; height: 0; margin: 0; padding: 0; } </style>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Animating 'all' properties including height and margin | Multiple style changes | Multiple reflows per frame | High paint cost due to layout changes | [X] Bad |
| Animating only opacity with will-change hint | Minimal style changes | No reflows | Low paint cost, GPU compositing | [OK] Good |
<transition> component in Vue?show changes from false to true?
<template>
<transition name="slide">
<div v-if="show">Hello</div>
</transition>
</template>
<style>
.slide-enter-active { transition: all 0.5s ease; }
.slide-enter-from { transform: translateX(-100%); opacity: 0; }
.slide-enter-to { transform: translateX(0); opacity: 1; }
</style><transition name="fade">
<div v-show="visible">Content</div>
</transition>
<style>
.fade-leave-active { transition: opacity 0.3s ease; }
.fade-leave-from { opacity: 1; }
.fade-leave-to { opacity: 0; }
</style>Pass the test and this pattern moves unknown