Performance: Virtual DOM and diffing mental model
HIGH IMPACT
This concept affects how quickly the page updates after user interaction by minimizing direct DOM changes.
<template>
<ul>
<li v-for="item in items" :key="item">{{ item }}</li>
</ul>
</template>
<script setup>
import { ref } from 'vue';
const items = ref(['a', 'b', 'c']);
</script>const list = document.getElementById('list'); list.innerHTML = ''; items.forEach(item => { const li = document.createElement('li'); li.textContent = item; list.appendChild(li); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct DOM manipulation (clearing and rebuilding) | Many nodes removed and added | N reflows for N items | High paint cost | [X] Bad |
| Vue virtual DOM diffing with keys | Only changed nodes updated | Single reflow for changes | Low paint cost | [OK] Good |