Performance: Why components are essential
MEDIUM IMPACT
Using components affects how the browser manages DOM updates and rendering efficiency.
<template>
<div>
<TitleComponent />
<ParagraphComponent text="Paragraph 1" />
<ParagraphComponent text="Paragraph 2" />
<ButtonComponent @click="update" />
</div>
</template>
<script setup>
import { ref } from 'vue'
import TitleComponent from './TitleComponent.vue'
import ParagraphComponent from './ParagraphComponent.vue'
import ButtonComponent from './ButtonComponent.vue'
const count = ref(0)
function update() {
count.value++
}
</script><template>
<div>
<h1>Title</h1>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<button @click="update">Click me</button>
</div>
</template>
<script setup>
import { ref } from 'vue'
const count = ref(0)
function update() {
count.value++
}
</script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single large component | Many nodes updated on any change | Multiple reflows per update | High paint cost due to large redraw | [X] Bad |
| Small reusable components | Only changed component nodes updated | Single or minimal reflows | Lower paint cost with targeted redraw | [OK] Good |