Importing Components
Part of the Fundamentals section of Coddy's Vue journey. Lesson 31 of 55.
A parent can render another SFC by importing it in script setup. The component name becomes a template tag, so this parent renders the content of BookNotice.vue.
import BookNotice from './BookNotice.vue';
// Parent template: <main><BookNotice /></main>The child file supplies its own template and optional state or styles. Use a relative path that matches the actual filename, including case. This separates a focused UI piece from the page that arranges it without requiring global registration.
Challenge
EasyCreate WelcomePanel.vue with a section containing an h2 reading Repair cafe and a paragraph reading Bring one broken item. Import and render it inside main#result in App.vue.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
7Reusable Components
Importing ComponentsIndependent InstancesPassing PropsProp Types and DefaultsRecap: Component Cards2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks