Performance: Component registration (global vs local)
This affects initial page load speed and runtime rendering performance by controlling how many components are loaded and parsed upfront versus on demand.
import { createApp } from 'vue'; import App from './App.vue'; const app = createApp(App); // Register locally inside component that uses it (e.g. in App.vue): // import MyButton from './MyButton.vue' // export default { // components: { MyButton } // } app.mount('#app');
import { createApp } from 'vue'; import MyButton from './MyButton.vue'; import App from './App.vue'; const app = createApp(App); app.component('MyButton', MyButton); // global registration app.mount('#app');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global registration | All components parsed upfront | Multiple reflows if many components render | Higher paint cost due to larger DOM | [X] Bad |
| Local registration | Only used components parsed | Fewer reflows as fewer components render initially | Lower paint cost with smaller DOM | [OK] Good |
<ParentComponent/>?
const ChildComponent = {
template: 'Child here
'
}
const ParentComponent = {
template: '',
components: { ChildComponent }
}
app.component('parent-component', ParentComponent)
app.mount('#app')Child here
only if the tag name matches the registered component name in kebab-case.const app = Vue.createApp({})
app.component('MyButton', {
template: 'Click me'
})
const AnotherComponent = {
template: ''
}
app.component('AnotherComponent', AnotherComponent)
app.mount('#app')Pass the test and this pattern moves unknown