Performance: Transition component for animations
MEDIUM IMPACT
This affects the rendering performance during element entry and exit animations, impacting visual stability and interaction responsiveness.
<template> <Transition name="fade"> <div v-if="show">Content</div> </Transition> </template> <script setup> import { ref } from 'vue' const show = ref(false) </script> <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" :style="{ transition: 'all 0.5s', opacity: show ? 1 : 0 }">Content</div> </template> <script setup> import { ref } from 'vue' const show = ref(false) </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct style toggle with v-if | Insert/remove DOM nodes abruptly | 2 per toggle | 2 paints per toggle | [X] Bad |
| Vue Transition component with CSS classes | Batched DOM updates with class toggling | 1 per animation | 1 paint per animation | [OK] Good |