🎓 A1Learner
🔍
0 of 50 lessons completed

Component Registration

Component registration tells Vue where a component can be used. Registration links a component name to its definition.

Local registration

The const name registers the child for this parent only.

const Greeting = defineComponent({
  template: '<p>Hello from a component.</p>'
})

Global registration

This line in main.js registers the child for the whole app.

app.component('Greeting', Greeting)

Using a registered component

The registered name works as a tag in the template.

<Greeting />

Example

<script setup>
import { defineComponent } from 'vue'
const Note = defineComponent({
  template: '<p>Registered locally.</p>'
})
</script>
<template>
  <div>
    <Note />
  </div>
</template>

Key points

  • Local registration makes a component usable in one parent only.
  • In script setup, naming the child as a const registers it locally.
  • Global registration makes a component usable in every template.
  • Global registration happens once, in main.js, with app.component.
  • A global name works in any component of the app.

In this example, Note is a small component with one paragraph. Naming it as a const registers it locally. The parent template uses Note once. The paragraph renders from the local registration.

Note

Local registration is the usual choice, so names stay close to where they are used.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does local registration do?