Performance: Defining components
MEDIUM IMPACT
This affects initial page load speed and rendering performance by controlling how Vue processes and renders UI parts.
<script setup> import MyButton from './MyButton.vue' </script> <template> <MyButton /> <MyButton /> <MyButton /> </template>
<script setup> const MyButton = { template: `<button>Click me</button>` } </script> <template> <MyButton /> <MyButton /> <MyButton /> </template>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline component definitions recreated each render | High (many nodes recreated) | Multiple reflows per render | High paint cost due to frequent DOM updates | [X] Bad |
| Imported single component reused multiple times | Low (nodes reused) | Single reflow per update | Lower paint cost due to efficient updates | [OK] Good |