Performance: v-if directive behavior
MEDIUM IMPACT
Controls whether elements are added or removed from the DOM, impacting rendering and layout recalculations.
<template>
<div v-show="showDetails">
<p>Details here</p>
</div>
</template><template>
<div v-if="showDetails">
<p>Details here</p>
</div>
</template>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| v-if toggling | Add/remove nodes | 1 reflow per toggle | Medium paint cost | [X] Bad for frequent toggling |
| v-show toggling | No DOM changes | No reflows | Low paint cost | [OK] Good for frequent toggling |