Menu
CoddyTech

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 icon

Challenge

Easy

Build 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals