Performance: Why templates matter in Vue
MEDIUM IMPACT
Templates affect how fast Vue can convert your code into DOM elements and update them efficiently.
<template><div>{{ someData }}</div></template><script setup>import { ref } from 'vue'; const someData = ref('Hello');</script><script setup>const htmlString = '<div>' + someData + '</div>';</script><template><div v-html="htmlString"></div></template>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using raw HTML with v-html | Many nodes replaced on update | Multiple reflows per update | High paint cost due to full block repaint | [X] Bad |
| Using Vue templates with interpolation | Minimal DOM updates | Single reflow per text change | Low paint cost with partial updates | [OK] Good |