0
0
Vueframework~20 mins

Component registration (global vs local) in Vue - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Component Registration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a locally registered component is used outside its parent?
Consider a Vue 3 app where ChildComp is registered locally inside ParentComp. What will happen if you try to use <ChildComp /> inside App.vue without registering it globally?
Vue
<script setup>
import ParentComp from './ParentComp.vue'
</script>
<template>
  <ParentComp />
  <ChildComp />
</template>
AThe app will compile but <code>ChildComp</code> will render as plain text <code>&lt;ChildComp /&gt;</code>.
BVue will render a blank space where <code>ChildComp</code> is used without errors.
CVue will log a console warning: <code>Failed to resolve component: ChildComp</code>.
DThe <code>ChildComp</code> will render normally because local registration is global by default.
Attempts:
2 left
💡 Hint
Think about where components are known and registered in Vue.
📝 Syntax
intermediate
1:30remaining
Which option correctly registers a component globally in Vue 3?
You want to register MyButton globally so it can be used anywhere in your app without importing. Which code snippet does this correctly?
Aapp.component('MyButton', MyButton)
Bapp.use(MyButton)
Capp.registerComponent('MyButton', MyButton)
Dapp.globalComponent('MyButton', MyButton)
Attempts:
2 left
💡 Hint
Look for the official Vue 3 method to register global components.
state_output
advanced
2:30remaining
What is the rendered output when a local component is registered with a different name?
Given this code, what will be rendered inside 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>
ANothing renders because the component name is mismatched
B<customchild></customchild>
CRuntime error: Unknown custom element <CustomChild>
D<div>Hello from Child</div>
Attempts:
2 left
💡 Hint
Check how local registration names affect usage inside the same component.
🔧 Debug
advanced
2:30remaining
Why does this globally registered component fail to render?
You registered 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')
AVue automatically converts PascalCase to kebab-case, so <code>&lt;my-widget /&gt;</code> should work; issue is elsewhere.
BComponent names are case-sensitive; use <code>&lt;MyWidget /&gt;</code> instead of kebab-case.
CYou must register components in kebab-case strings to use kebab-case tags.
DThe component must be imported with a .vue extension to render.
Attempts:
2 left
💡 Hint
Think about Vue's handling of component names in templates.
🧠 Conceptual
expert
3:00remaining
Why prefer local registration over global in large Vue apps?
In a large Vue 3 app, why is local component registration often preferred over global registration?
ALocal registration allows components to be used anywhere without importing, reducing code size.
BLocal registration improves app startup time by loading only needed components per view.
CGlobal registration causes components to lose reactivity and state management features.
DGlobal registration automatically scopes CSS which can cause style conflicts.
Attempts:
2 left
💡 Hint
Think about performance and code organization in big apps.