Single-File Components
Part of the Fundamentals section of Coddy's Vue journey. Lesson 2 of 55.
A single-file component keeps its JavaScript, template and styles in one .vue file. This example has a template with a heading and a paragraph; those elements become the visible component.
<template>
<section><h2>Book club</h2><p>Friday meetings</p></section>
</template>The supplied main.js imports App.vue and calls createApp(App).mount('#app'). The matching element lives in index.html. Write page content inside the template, not in the mount file. A <script setup> block will hold component logic in later lessons.
Challenge
EasyBuild a reading-room card in App.vue. Render an h1 with id="result" and text Reading room, then a paragraph with id="hours" and text Open until 18:00. Keep the supplied mount files.
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
2Reactive 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