Performance: Single File Components concept
This affects initial page load speed and rendering performance by how Vue bundles and processes component code.
<template> <ChildComponent /> </template> <script> import { defineAsyncComponent } from 'vue'; export default { components: { ChildComponent: defineAsyncComponent(() => import('./ChildComponent.vue')) } }; </script>
<template><div>...</div></template> <script>export default { /* large logic */ }</script> <style>/* large styles */</style>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| One large SFC | Moderate (single root) | 1 reflow | High paint cost due to delayed script | [X] Bad |
| Multiple small SFCs with lazy loading | Multiple small DOM trees | Few reflows | Lower paint cost due to faster script load | [OK] Good |
<template>
<div>{{ message }}</div>
</template>
<script setup>
const message = 'Hello Vue!'
</script><template>
<button @click='increment'>Count: {{ count }}</button>
</template>
<script setup>
let count = 0
function increment() {
count++
}
</script>title prop and displays it inside an <h1> tag. Which of the following is the correct way to define the prop and use it in the template?Pass the test and this pattern moves unknown