Bird
Raised Fist0
Vueframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main difference between global and local component registration in Vue?
easy
A. Global registration requires importing components manually, local does not.
B. Local registration makes a component available everywhere, global limits it to one component.
C. Global registration makes a component available everywhere, local limits it to one component.
D. Local registration automatically registers components globally.

Solution

  1. Step 1: Understand global registration

    Global registration means the component can be used in any template without importing it again.
  2. Step 2: Understand local registration

    Local registration means the component is only available inside the component where it is registered.
  3. Final Answer:

    Global registration makes a component available everywhere, local limits it to one component. -> Option C
  4. Quick Check:

    Global = everywhere, Local = one component [OK]
Hint: Global = everywhere, local = one place only [OK]
Common Mistakes:
  • Confusing global with local availability
  • Thinking local registration is automatic
  • Assuming global requires manual import every time
2. Which of the following is the correct syntax to register a component locally inside a Vue component?
easy
A. export default { globalComponents: { MyComponent } }
B. Vue.component('MyComponent', MyComponent)
C. import MyComponent from './MyComponent.vue';
D. components: { MyComponent }

Solution

  1. Step 1: Identify local registration syntax

    Local registration uses the components option inside the component definition object.
  2. Step 2: Match correct syntax

    The syntax is components: { MyComponent } to register locally.
  3. Final Answer:

    components: { MyComponent } -> Option D
  4. Quick Check:

    Local registration uses components: { } [OK]
Hint: Local registration uses components: { ComponentName } [OK]
Common Mistakes:
  • Using Vue.component() for local registration
  • Confusing import statement with registration
  • Trying to use globalComponents option which doesn't exist
3. Given this code, what will be the output when rendering <ParentComponent/>?
const ChildComponent = {
  template: '

Child here

' } const ParentComponent = { template: '
', components: { ChildComponent } } app.component('parent-component', ParentComponent) app.mount('#app')
medium
A.

Child here

B. Error: Unknown custom element
C.
D.

Child here

Solution

  1. Step 1: Check local registration in ParentComponent

    ChildComponent is registered locally inside ParentComponent using components: { ChildComponent }.
  2. Step 2: Understand template rendering

    The tag inside ParentComponent's template will render ChildComponent's template

    Child here

    only if the tag name matches the registered component name in kebab-case.
  3. Step 3: Identify the issue

    The component is registered as ChildComponent but used as , which Vue treats as a different tag. Since 'child-component' is not globally registered, Vue will throw an unknown custom element error.
  4. Final Answer:

    Error: Unknown custom element <child-component> -> Option B
  5. Quick Check:

    Component names are case-sensitive and must match usage [OK]
Hint: Component names must match tag names exactly or use kebab-case [OK]
Common Mistakes:
  • Assuming PascalCase component names automatically match kebab-case tags
  • Forgetting to register components globally when using kebab-case tags
  • Expecting local registration to work with mismatched tag names
4. What is wrong with this Vue code snippet?
const app = Vue.createApp({})

app.component('MyButton', {
  template: 'Click me'
})

const AnotherComponent = {
  template: ''
}

app.component('AnotherComponent', AnotherComponent)

app.mount('#app')
medium
A. The tag inside AnotherComponent template should be lowercase .
B. MyButton component is not registered globally.
C. AnotherComponent is missing local registration of MyButton.
D. Vue.createApp() cannot register components.

Solution

  1. Step 1: Check component registration

    MyButton is registered globally using app.component('MyButton', ...), so it is available everywhere.
  2. Step 2: Check template tag casing

    Vue requires component tags in templates to be kebab-case or PascalCase but HTML is case-insensitive, so should be .
  3. Final Answer:

    The <MyButton /> tag inside AnotherComponent template should be lowercase <my-button />. -> Option A
  4. Quick Check:

    Component tags must be kebab-case in templates [OK]
Hint: Use kebab-case for component tags in templates [OK]
Common Mistakes:
  • Using PascalCase tags directly in templates
  • Thinking global registration needs import in every component
  • Assuming Vue.createApp() can't register components
5. You have a button component used in many places and a modal component used only inside one page component. How should you register them for best practice?
hard
A. Register the button component globally and the modal component locally inside the page component.
B. Register both components globally for consistency.
C. Register both components locally inside each component that uses them.
D. Register the modal component globally and the button component locally.

Solution

  1. Step 1: Consider usage frequency

    The button is used many places, so global registration avoids repeated imports and registrations.
  2. Step 2: Consider component scope

    The modal is used only inside one page component, so local registration keeps scope limited and reduces global clutter.
  3. Final Answer:

    Register the button component globally and the modal component locally inside the page component. -> Option A
  4. Quick Check:

    Global for many uses, local for few uses [OK]
Hint: Global for shared, local for limited use components [OK]
Common Mistakes:
  • Registering rarely used components globally unnecessarily
  • Registering widely used components locally repeatedly
  • Ignoring app size and performance considerations
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard