ChildComp is registered locally inside ParentComp. What will happen if you try to use <ChildComp /> inside App.vue without registering it globally?<script setup> import ParentComp from './ParentComp.vue' </script> <template> <ParentComp /> <ChildComp /> </template>
Locally registered components are only known inside the component where they are registered. Using them outside without global registration causes Vue to not recognize the tag, resulting in a console warning.
MyButton globally so it can be used anywhere in your app without importing. Which code snippet does this correctly?The app.component() method registers a component globally in Vue 3. Other options are not valid Vue API methods.
App.vue?
// ChildComp.vue
<template><div>Hello from Child</div></template>
// ParentComp.vue
<script setup>
import CustomChild from './ChildComp.vue'
</script>
<template>
<CustomChild />
</template>
// App.vue
<template>
<ParentComp />
</template>
Inside ParentComp, the component is registered as CustomChild and used as such, so it renders correctly. The name change only affects usage inside ParentComp.
MyWidget globally but when you use <my-widget /> in your template, nothing shows. Why?
const app = createApp(App)
app.component('MyWidget', MyWidget)
app.mount('#app')Vue automatically converts PascalCase component names to kebab-case in templates, so <my-widget /> is valid for 'MyWidget'. The problem is likely elsewhere, such as the component code or mounting.
Local registration helps keep the app lightweight by only loading components where needed, improving startup time and maintainability. Global registration loads all components upfront, which can slow down the app.