By the end of the previous module, App.vue contained almost all of Colmena Bookings: the header with the clock, the catalogue with its filters and its states, the spec sheet for the selected room, seat management, the search box and the booking form with its validation. It works, but it is a file hundreds of lines long in which it is hard to find anything, in which any change can break something else and from which we cannot reuse a single piece. Components are Vue's answer to this problem: they let you split the interface into independent pieces, each with its own template, logic and styles, which are combined like building blocks. In this lesson you will see exactly what a component is, how it is registered so that it can be used, which naming and folder conventions a professional project follows, why each use of a component has its own state and, above all, how to decide what to extract. We will apply all this by taking the first pieces out of App.vue: AppHeader (with ReceptionClock inside it) and ShortcutsHelp.
Contents
- What a component is and why the interface should be split up
- Colmena's component tree
- The Single File Component (SFC) as a unit
- Local registration and global registration
- Naming conventions
- Folder conventions
- Each instance has its own state
- How to decide what to extract
- Case study:
AppHeaderandShortcutsHelp
- What a component is and why the interface should be split up
A component is a reusable, self-contained piece of the interface. It brings together three things that belong together:
- Template: what is displayed (the markup).
- Logic: what state it has and how it reacts (the script).
- Styles: how it looks (the CSS, usually with its own scope).
You have already used components without studying them in depth: App.vue is a component, and so are ReceptionClock and RoomCard. What changes now is the approach: instead of one giant component, we will build the application as a composition of small components.
Splitting up the interface brings some very concrete advantages:
| Advantage | What it means in practice |
|---|---|
| Readability | Each file fits on the screen and deals with a single thing. To change the clock you open ReceptionClock.vue, not a 900-line file. |
| Reuse | A component written once is used in many places: one card per room, the same button throughout the application. |
| Isolation | A component's state and styles do not interfere with the others. A local change has local effects. |
| Teamwork | Several people can work on different components at the same time without treading on each other's toes in version control. |
| Testing | A small component with a clear input and output can be tested in isolation (you will see this in module 8). |
| Performance | Vue updates each component separately: if the clock's state changes, only the clock is re-rendered. |
The last point deserves an explanation. Each component has its own render effect: Vue records which reactive data its template reads and, when one of them changes, it re-renders only that component. That is why, when ReceptionClock changes the time every second, only the clock is re-rendered and not App.vue: the clock was already a separate component. By contrast, every letter you type in the booking form causes the entire template of App.vue to be re-evaluated, catalogue included, because the form lives inside it. Once the interface is split up, each piece updates on its own.
- Colmena's component tree
Components are nested: one component uses others in its template, which in turn use others. The result is a component tree, with App at the root. We call the component that uses another the parent, and the component being used the child.
This is the tree that Colmena Bookings will have by the end of the module (we will create the ones that do not exist yet lesson by lesson):
flowchart TD
App["App.vue<br/>(orchestrator)"]
App --> Header["AppHeader"]
Header --> Clock["ReceptionClock"]
App --> Help["ShortcutsHelp"]
App --> Filters["RoomFilters"]
App --> List["RoomList"]
List --> Card["RoomCard<br/>(one per room)"]
Card --> Badge["StatusBadge"]
Card --> Button1["BaseButton"]
App --> Panel["BasePanel<br/>(selected room)"]
App --> Form["BookingForm"]
Form --> Field["TextField"]
Form --> Button2["BaseButton"]
Notice three ideas that will guide the whole module:
App.vuewill end up as an orchestrator: it keeps the state that several pieces share (the loaded catalogue, the selected room, the bookings) and coordinates its children, but it no longer draws every detail.- Some pieces appear many times: there will be one
RoomCardfor each visible room, andBaseButtonwill be everywhere. - Data will have to travel through the tree:
RoomListneeds the rooms thatApploads, and when the user clicks "Book" on a card,BookingFormwill have to find out. How data travels from parents to children and from children to parents is the subject of the next few lessons.
You can see your application's real tree at any time in the Components tab of Vue DevTools. Right now you will see only three nodes: App, ReceptionClock and RoomCard.
- The Single File Component (SFC) as a unit
In Vite projects, each component lives in a Single File Component (SFC): a .vue file with up to three blocks. You already know its anatomy from Creating Your First Vue Application; let's review it now from the point of view of component design:
<!-- src/components/ReceptionClock.vue -->
<script setup>
// 1. Logic: state, computed properties, functions, lifecycle.
// Everything declared here is PRIVATE to each instance of the component.
import { ref, onMounted, onUnmounted } from 'vue'
const time = ref('')
// ...
</script>
<template>
<!-- 2. Template: what the component renders. It only sees what its script declares. -->
<p class="clock">Reception · {{ time }}</p>
</template>
<style scoped>
/* 3. Styles: with scoped, they only affect the elements of THIS component. */
.clock {
margin: 0;
}
</style>The SFC is the unit of encapsulation:
- The script is private. The variables and functions in
<script setup>exist only for that component. Another component cannot read the clock'stime, however much it wants to. To communicate, components will use explicit channels: props and events (03-02), slots (03-04) and a few more that we will go over in 03-07. - The template only sees its own script. If you write
{{ catalog }}in a child's template, Vue will not look forcatalogin the parent: it will warn you that the property is not defined. scopedstyles do not leave the component. As you saw in Class and Style Bindings,scopedadds adata-v-...attribute to the component's elements and rewrites the selectors. An important consequence for this module: the styles inApp.vuewill not reach the elements of the components we extract (except each child's root element). When we move markup that used the.buttonclass, we will have to take its styles along too.
An SFC is compiled into an ordinary JavaScript object (the component definition object), which contains the render function generated from the template and the script's code. That is why a component can be imported like any other module: import ReceptionClock from './components/ReceptionClock.vue' gives you that object.
- Local registration and global registration
To use a component in another component's template, Vue has to know that it exists. This is called registering the component, and there are two ways of doing it.
4.1 Local registration: importing in <script setup>
This is what you have been doing since module 1. In <script setup>, importing a component is enough to be able to use it in the template:
<script setup>
import ReceptionClock from './components/ReceptionClock.vue'
</script>
<template>
<ReceptionClock />
</template>The compiler sees that ReceptionClock is a script variable whose name matches the tag, and connects the two. The component is only available in the file that imports it: if another component wants to use it, it will have to import it as well.
With the Options API (existing code you will come across often), local registration is done with the components option:
import ReceptionClock from './components/ReceptionClock.vue'
export default {
components: { ReceptionClock }
}4.2 Global registration: app.component
The application instance you saw in Understanding the Vue Instance: Application, Components and Lifecycle has an app.component(name, component) method that registers a component for the whole application. After that, any template can use it without importing it:
// src/main.js (just as an example: we will NOT do this in Colmena)
import { createApp } from 'vue'
import App from './App.vue'
import ReceptionClock from './components/ReceptionClock.vue'
const app = createApp(App)
app.component('ReceptionClock', ReceptionClock) // available in any template
app.mount('#app')4.3 Which one should you choose?
| Aspect | Local registration (importing) | Global registration (app.component) |
|---|---|---|
| Tree-shaking | Yes: if a component is not imported anywhere, the bundler removes it from the final build | No: a globally registered component always ends up in the bundle, even if nobody uses it |
| Clarity of dependencies | Complete: the import says where each component comes from; the editor can jump to its definition |
Poor: when you read <ReceptionClock /> you do not know where it is defined without searching for it |
| Lazy loading | Lets you split the code and load components on demand (03-06) | Whatever is registered at start-up is loaded at start-up |
| Convenience | You have to write the import in every file that uses it |
It is registered once and used everywhere |
| Risk of collisions | None: each file decides which names it uses | All the components share a global namespace |
| Typical use | The vast majority of an application's components | Components from a UI library installed as a plugin (07-01) |
The course's recommendation: always use local registration. The convenience of global registration does not make up for losing tree-shaking and traceability. If writing imports feels tedious, there are tools such as unplugin-vue-components that generate them automatically during the build, keeping the advantages of local registration; we will not use them in the course so that you can always see where each piece comes from.
- Naming conventions
The official Vue style guide sets out conventions that the community follows almost universally. These are the ones we will apply:
| Convention | Correct example | Incorrect example | Why |
|---|---|---|---|
| PascalCase for the file name and the component name | RoomCard.vue |
room-card.vue, roomCard.vue |
It stands out at a glance from HTML elements and matches the name of the imported variable |
| PascalCase in SFC templates | <RoomCard /> |
<room-card /> |
It makes clear that it is a component. (In templates written directly in the page's HTML, like the CDN example in the first lesson, you have to use kebab-case, because the browser converts names to lower case) |
| Multi-word names | ReceptionClock, AppHeader |
Clock, Header |
It avoids collisions with present or future HTML elements: Clock does not clash with anything today, but Header would clash with <header>. The only exception is the root component, App |
| Self-closing tags when they have no content | <ReceptionClock /> |
<ReceptionClock></ReceptionClock> |
Shorter, and it makes clear that it receives no content |
Base marker for generic components |
BaseButton, BasePanel |
MyButton, Button |
It groups and identifies the presentational components with no business logic, which are used throughout the application |
| Names that go from the general to the specific | RoomList, RoomCard, RoomFilters |
ListRooms mixed with RoomCard |
Related components are sorted together in the file explorer |
| Meaningful words in full | BookingForm |
BkngFrm |
No abbreviations: the name should be understandable without opening the file |
A note on the Base marker: the official guide proposes it as a prefix (BaseButton, BaseIcon), and in English the prefix reads perfectly naturally, so in Colmena we follow the guide to the letter: BaseButton ("base button"), BasePanel, BaseModal. What matters is not the position, but that there is a single criterion, applied consistently throughout the project. The ESLint you configured in module 1 includes the vue/multi-word-component-names rule, which warns you if you create a single-word component.
The file name is also the component's name: with <script setup>, Vue infers it from the file name, and it is the one you will see in Vue DevTools and in the warning messages in the console. A good file name therefore also makes debugging easier.
- Folder conventions
Vue does not impose any folder structure, but the project created with npm create vue@latest already comes with src/components/. In Colmena we will organise it like this:
src/
├── App.vue ← orchestrator
├── main.js
├── assets/
│ └── main.css ← global styles
├── api/ ← simulated API (rooms.js; bookings.js will come later)
├── data/
│ └── rooms.js
└── components/
├── base/ ← generic and reusable, with no Colmena logic
│ ├── BaseButton.vue (03-04)
│ ├── TextField.vue (03-03)
│ └── BasePanel.vue (03-04)
├── AppHeader.vue ← specific to Colmena
├── ShortcutsHelp.vue
├── ReceptionClock.vue
├── RoomCard.vue
├── RoomList.vue (03-02)
├── StatusBadge.vue (03-02)
├── RoomFilters.vue (03-03)
└── BookingForm.vue (03-03)components/base/contains the generic presentational components: they know nothing about rooms or bookings and could be copied into another project as they are. As well asBaseButtonandBasePanel, we will keepTextFieldhere, which is also generic even though its name is descriptive: in this folder, the location itself is the marker.components/(the root) contains the domain-specific components for Colmena: they know the data model for rooms and bookings.- When the folder grows, it can be subdivided by feature (
components/catalog/,components/bookings/). We will do this in 03-06. - In module 4 a sibling folder will appear,
views/, for the components that represent complete pages associated with a route.
A practical rule: if a component in base/ starts importing things from data/ or api/, it is no longer generic and it is in the wrong folder.
- Each instance has its own state
A .vue file is a definition: a mould. Every time you write the component's tag in a template, Vue creates a new instance from that mould, and the <script setup> code runs once per instance. That is why each instance has its own refs, its own computed properties and its own watchers.
Check this with RoomCard. Temporarily add a second card at the end of <main> in App.vue, just after the one that is already there:
Now click "+ Attendee" three times on the first card and once on the second:
| First card | Second card | |
|---|---|---|
attendees |
3 | 1 |
| Occupancy bar | 38% | 13% |
| Console message on mounting | [RoomCard] Panal Room ready |
[RoomCard] Panal Room ready (again) |
The two cards share the code, but not the state: each one has its own attendees. In Vue DevTools you will see two RoomCard nodes and, when you select each one, its own value of attendees.
flowchart LR
Def["RoomCard.vue<br/>(definition: the mould)"]
Def -->|"creates"| I1["Instance 1<br/>attendees = 3"]
Def -->|"creates"| I2["Instance 2<br/>attendees = 1"]
The experiment also reveals the big limitation of our RoomCard: both instances show the Panal Room, because the room is written inside the component (rooms.find((r) => r.id === 'panal')). A card that can only show one room is no use for the catalogue. What we need is for the parent to tell each instance which room to show, just as an <img> receives its src. Those are props, and they are the first thing we will tackle in the next lesson. For now, leave a single <RoomCard />.
7.1 What is shared: the module scope
There is a trap that many beginners fall into. The <script setup> code runs per instance, but whatever you import from another JavaScript module is the same object for everyone. For example, RoomCard imports rooms from src/data/rooms.js: if one instance modified room.capacity, the other would see the change, because both read the same object from the exported array. The same happens with the variables declared in an ordinary <script> block (without setup), which runs only once, when the module is loaded:
<script>
// Ordinary <script> block: runs ONCE, when the module is imported.
// This variable is shared by ALL the instances.
let cardsCreated = 0
</script>
<script setup>
// <script setup> block: runs once PER INSTANCE.
cardsCreated++
const cardNumber = cardsCreated // specific to this instance
</script>Sometimes that behaviour is exactly what you want (a global counter, a cache), and in Component Communication we will take advantage of it deliberately. But if you are not looking for it, it is a hard bug to spot: each instance's state is always declared inside <script setup>.
- How to decide what to extract
Splitting is good, but splitting too much has a cost as well: a three-line component that is used only once forces you to jump between files to understand something trivial. These questions will help you decide:
| Question | If the answer is "yes"... | Example in Colmena |
|---|---|---|
| Is this block repeated, or will it be, in several places? | Extract it: this is the clearest case | Each room in the catalogue → RoomCard |
| Does it have a responsibility you can describe in one sentence without using "and"? | It is a good candidate | "Shows the application header" → AppHeader |
| Does it have its own state that nobody else cares about? | Extracting it encapsulates that state | Showing or hiding the help → ShortcutsHelp |
| Is the current component over 200-300 lines long, or is it hard to find things in it? | Look inside it for blocks with a clear responsibility | App.vue at the end of module 2 |
| Is it a generic interface element (button, field, panel)? | Extract it into components/base/ |
BaseButton, TextField |
| Do you want to be able to test it in isolation? | A small component is easier to test | BookingForm and its validations |
And some signs that you should not extract it (yet):
- The block is two or three elements with no logic that appear only once.
- To extract it you would have to pass it ten pieces of data from the parent and have it return another ten: you have probably cut in the wrong place.
- You cannot give it a clear name. A component that cannot be named does not have a well-defined responsibility.
A tip on method: extract first whatever does not need to communicate with anyone. Self-sufficient pieces, which do not depend on data from the parent, can be taken out right now with what you already know. That is exactly what we are going to do.
- Case study:
AppHeader and ShortcutsHelp
AppHeader and ShortcutsHelpLet's go through App.vue with the criteria above. There are two blocks that do not depend on anything else in the application:
- The header: the title, today's date, the reception clock with its button to show or hide it, and the reception note. It uses
today,formatDate,receptionNote,showClockandtoggleClock, which nobody else needs... except for one detail:todayis also used to calculatetodayISOin the form. We will solve this by keepingtodayinApp.vueas well until the form has its own component. - The shortcuts help: the "?" button and the paragraph with
v-show. It only usesshowHelp.
The rest (catalogue, selected room, form) needs to exchange data with App, so it will have to wait for the next few lessons.
9.1 Shared styles
Before moving any markup, let's deal with the problem flagged in section 3. The header and help buttons use the .button class, and the notes use the .note class, both defined in the <style scoped> of App.vue. If we move those elements to another component, they will lose their styles, because App's data-v-... will no longer be on them.
The temporary solution is to turn those two classes into global styles. Cut the .button, .button--active and .note rules from App.vue and paste them into src/assets/main.css:
/* src/assets/main.css — add at the end */
/* Temporary shared styles: in 03-04 .button will move into BaseButton */
.button {
padding: 0.6rem 1.2rem;
border: none;
border-radius: 6px;
background: var(--color-honey-dark);
color: white;
cursor: pointer;
}
.button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.button--active {
outline: 3px solid var(--color-text);
outline-offset: 2px;
}
.note {
padding: 0.5rem 1rem;
border-left: 4px solid var(--color-honey);
background: white;
}Global styles work, but they bring back the risk that scoped avoided: any component that uses the .button class for something else will receive these styles. That is why this is temporary: in Slots we will create BaseButton, which will carry its own encapsulated styles.
9.2 AppHeader.vue
Create src/components/AppHeader.vue:
<script setup>
import { ref } from 'vue'
import ReceptionClock from './ReceptionClock.vue'
// Data that does not change
const today = new Date()
// Fixed text written by us: it is safe to display it with v-html
const receptionNote = 'The <strong>Néctar Room</strong> closes at 18:00 today.'
// The header's own state: nobody else cares whether the clock is visible
const showClock = ref(true)
// Long date format in British English: "Tuesday 3 November"
function formatDate(date) {
return date.toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long' })
}
function toggleClock() {
showClock.value = !showClock.value
}
</script>
<template>
<header class="header">
<div class="header__title">
<h1>Colmena Bookings</h1>
<p>Room booking for the Colmena coworking space · {{ formatDate(today) }}</p>
</div>
<div class="header__reception">
<ReceptionClock v-if="showClock" />
<button class="button" @click="toggleClock">
{{ showClock ? 'Hide clock' : 'Show clock' }}
</button>
</div>
<p class="note header__note" v-html="receptionNote"></p>
</header>
</template>
<style scoped>
.header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1.5rem 2rem;
background: var(--color-honey);
}
.header h1 {
margin: 0;
}
.header__reception {
display: flex;
align-items: center;
gap: 0.75rem;
}
.header__note {
flex-basis: 100%;
margin: 0;
}
</style>Let's analyse the decisions:
import ReceptionClock from './ReceptionClock.vue': the path is relative toAppHeader's folder (both are incomponents/). The clock is no longer a child ofAppand becomes a grandchild: it is now a child ofAppHeader.Appno longer needs to import it.showClockandtoggleClocktravel with the header. This is state that only the header cares about; by moving it,App.vueis freed of it. We take the opportunity to make the button say "Hide clock" or "Show clock" as appropriate, which is clearer than the old "Show/hide clock".- The reception note also moves into the header: it is reception information, like the clock.
- The
.headerstyles move fromApp.vue(delete them there) and are extended with a flexible layout: the title on the left, the clock on the right and the note taking up the whole bottom row (flex-basis: 100%). .buttonand.notework because they are now global.
9.3 ShortcutsHelp.vue
Create src/components/ShortcutsHelp.vue:
<script setup>
import { ref } from 'vue'
const showHelp = ref(false)
</script>
<template>
<button
class="button button--help"
:aria-expanded="showHelp ? 'true' : 'false'"
aria-controls="shortcuts-help"
@click="showHelp = !showHelp"
>
?
</button>
<p v-show="showHelp" id="shortcuts-help" class="note">
Shift + click on "Book a seat" books 5 seats in one go. In the search box, Enter applies the
search and Escape clears it.
</p>
</template>
<style scoped>
.button--help {
border-radius: 50%;
width: 2.2rem;
height: 2.2rem;
padding: 0;
}
</style>- The component encapsulates its only piece of data,
showHelp. From the outside, writing<ShortcutsHelp />is all it takes. - We add
aria-expandedandaria-controls: the screen reader will announce that the button expands some content and whether it is open or closed. Since we are reviewing the block anyway, this is a good moment to improve its accessibility. - Notice that the template has two root elements (the button and the paragraph). Vue 3 allows this; in Template Refs and Fallthrough Attributes we will see what consequences this has when a parent passes it attributes such as
class.
9.4 A lighter App.vue
Now remove from App.vue everything that has moved out. In the <script setup>:
// Imports: replace the ReceptionClock one with the two new components
import AppHeader from './components/AppHeader.vue'
import ShortcutsHelp from './components/ShortcutsHelp.vue'
import RoomCard from './components/RoomCard.vue'
// (the rest of the imports do not change)
// DELETE these declarations, which now live in AppHeader or ShortcutsHelp:
// const receptionNote = ...
// const showClock = ref(true)
// const showHelp = ref(false)
// function formatDate(date) { ... }
// function toggleClock() { ... }
// KEEP const today = new Date(): todayISO uses it in the booking formIn the template, the whole header becomes a single tag, and the note, the clock button and the help block at the start of <main> are replaced by <ShortcutsHelp />:
<template>
<AppHeader />
<main class="content">
<ShortcutsHelp />
<!-- From here on, no changes: catalogue, search box, selected room,
booking form and <RoomCard /> -->
</main>
</template>And in the <style scoped> of App.vue, delete the .header and .header h1 rules (they are now in AppHeader) and the .button, .button--active and .note rules (they are now global).
9.5 Try it
- The application should look the same as before, with the header rearranged. Click "Hide clock": in the console you will see
ReceptionClock's unmounting message, just as in module 1. - Open Vue DevTools: the tree now shows
App→AppHeader→ReceptionClock, as well asShortcutsHelpandRoomCard. SelectAppHeaderand changeshowClockfrom the panel: the header reacts. - Select
Appin DevTools:showClockandshowHelpno longer appear in its state. The root component is starting to slim down. - Inspect the
<header>with the browser's developer tools: it has adata-v-...attribute that is different from the one on the elements in<main>, because it belongs to another component.
Common Mistakes and Tips
- Forgetting to import the component. If you write
<AppHeader />without theimport, Vue will showFailed to resolve component: AppHeaderin the console and render nothing. In<script setup>, no import means no component. - Getting the relative path wrong. Inside
components/, another component in the same folder is imported with./ReceptionClock.vue, not with./components/ReceptionClock.vue. If relative paths confuse you, use the@alias:@/components/ReceptionClock.vueworks from any file. - Losing styles when moving markup. The parent's
scopedstyles do not reach the child's elements. Move the rules along with the markup, or make them global deliberately. - Single-word names (
Header.vue,Clock.vue). ESLint will warn you; use at least two words. - Registering components globally for convenience. You lose tree-shaking and traceability. Import locally.
- Declaring state in an ordinary
<script>or in an imported module in the belief that it is per instance. It will be shared by all the instances. - Extracting components you cannot name. If you cannot find a clear name, you are probably cutting in the wrong place.
- Tip: when you extract a component, make the change in small steps and check that the application still works after each one (create the file, move the markup into it, move the script, move the styles, replace it in the parent). With HMR, each step can be checked in seconds.
Exercises
Exercise 1. Show that each instance of ShortcutsHelp has its own state: put two <ShortcutsHelp /> one after the other in App.vue, open only the first help and explain what you observe. Then explain what would happen if you moved const showHelp = ref(false) into an ordinary <script> block (without setup) in the same file and exported it from there. When you have finished, leave a single <ShortcutsHelp />.
Exercise 2. Classify each of these current blocks of App.vue according to whether it should be extracted into a component now (it is self-sufficient), later (it needs to communicate with the parent) or not at all (it is not worth it), and justify each answer in one sentence: (a) the "N free rooms out of M · showing K" paragraph; (b) each <li> in the room catalogue; (c) the whole booking form; (d) the floor, capacity and sort filter buttons; (e) a BoldText component that would merely wrap a <strong>.
Exercise 3. Create an AppFooter.vue component in src/components/ with a <footer> that shows "Colmena Bookings · Coworking Colmena · © 2026" and a "Usage rules" link to /rules.html. Use it in App.vue after <main>. Give it its own scoped styles (background var(--color-honey), centred text). Which folder should it go in, and why not in components/base/?
Solutions
Solution 1. When you open the first help, only its paragraph expands: the second one stays closed. Each <ShortcutsHelp /> creates an instance that runs its own <script setup>, and therefore creates its own ref(false). In Vue DevTools you will see two ShortcutsHelp nodes, one with showHelp: true and the other with false.
If the ref were declared in an ordinary <script>:
<script>
import { ref } from 'vue'
export const showHelp = ref(false) // runs ONCE when the module is loaded
</script>
<script setup>
// The template can still use showHelp, but it is no longer per instance
</script>that block runs only once, when the module is loaded, so both instances would share the same ref: clicking either "?" button would open or close both help texts at once. What is more, any file could import it and modify it. It is shared state, not the component's own.
There is one more detail: with two instances, the paragraph's id="shortcuts-help" would be repeated on the page, and ids must be unique. In v-model on Your Own Components you will see useId(), which generates unique identifiers per instance.
Solution 2.
- (a) The free rooms paragraph: not at all. It is a line of text with no logic of its own that appears only once; extracting it would mean passing it three numbers to render one sentence.
- (b) Each
<li>in the catalogue: later. It is the clearest case for extraction (it is repeated for every room and has quite a lot of markup), but it needs to receive its room and notify the parent when "Select" is clicked. This is whatRoomCardwill do with props and events in the next lesson. - (c) The booking form: later. It has a crystal-clear responsibility and a lot of code of its own, but it needs to know which room is selected and to hand the created booking over to the parent. We will extract it in 03-03.
- (d) The filter buttons: later. They form a unit with a clear name (
RoomFilters), butAppneeds the chosen values to filter the catalogue: communication in both directions is required (v-modelon components will solve this). - (e)
BoldText: not at all. It adds nothing to<strong>: no logic, no styles, no abstraction. It would be a level of indirection with no benefit.
Solution 3.
<!-- src/components/AppFooter.vue -->
<template>
<footer class="footer">
<p>Colmena Bookings · Coworking Colmena · © 2026</p>
<a href="/rules.html">Usage rules</a>
</footer>
</template>
<style scoped>
.footer {
padding: 1.5rem 2rem;
background: var(--color-honey);
text-align: center;
}
.footer p {
margin: 0 0 0.5rem;
}
</style><!-- In App.vue -->
<script setup>
import AppFooter from './components/AppFooter.vue'
// ...
</script>
<template>
<AppHeader />
<main class="content"><!-- ... --></main>
<AppFooter />
</template>A component with no state or logic can also have an empty <script setup> or, as here, no script block at all. It goes in components/ (the root) because it contains information specific to Colmena (the name of the coworking space, a link to its rules): it could not be copied into another project as it is. components/base/ is only for generic pieces.
Conclusion
A component brings template, logic and styles together in a reusable piece, and a Vue application is a tree of components with App at the root. The SFC is the unit of encapsulation: its script is private, its template only sees its own script and its scoped styles do not leave it. To use a component you have to register it: local registration (importing it in <script setup>) is the recommended option over global registration (app.component), because it keeps tree-shaking and makes the dependencies clear. Components are named in PascalCase, with several words, and the generic ones are marked with Base and grouped in components/base/. Each use of a component creates an instance with its own state, except for whatever is declared outside <script setup>. To decide what to extract, look for blocks that are repeated, that have a responsibility you can name or that have their own state. Colmena now has AppHeader (with ReceptionClock inside it) and ShortcutsHelp, and App.vue has shed its first responsibilities.
But the pieces we have extracted are the easy ones: those that do not need to talk to anybody. The experiment with the two cards has made the next step clear: RoomCard always shows the Panal Room because it has no way of receiving the room it should render, or of notifying its parent when the user selects it. In Props and Custom Events we will learn these two communication channels, and with them we will turn the catalogue into a RoomList of real cards.
Vue.js Course
Module 1: Introduction to Vue.js
- What Is Vue.js?
- Setting Up the Development Environment
- Creating Your First Vue Application
- Understanding the Vue Instance: Application, Components and Lifecycle
- Options API and Composition API: Two Ways to Write Components
Module 2: Vue.js Basics
- Template Syntax
- Reactivity: ref and reactive
- Data Binding
- Event Handling
- Computed Properties and Watchers
- Class and Style Bindings
- Conditional Rendering
- List Rendering
- Forms with v-model
Module 3: Vue.js Components
- Introduction to Components
- Props and Custom Events
- v-model on Your Own Components
- Slots
- Template Refs and Fallthrough Attributes
- Dynamic and Async Components
- Component Communication
Module 4: Vue Router
- Introduction to Vue Router
- Setting Up Vue Router
- Dynamic Routes
- Nested Routes
- Programmatic Navigation and Query Parameters
- Navigation Guards
Module 5: State Management with Vuex and Pinia
- Introduction to Vuex
- State, Getters, Mutations and Actions
- Vuex Modules
- Using Vuex in Components
- Advanced Vuex Patterns
- Pinia: The Recommended State Management for Vue 3
- Migrating from Vuex to Pinia
Module 6: Vue.js Directives
Module 7: Vue.js Plugins
Module 8: Testing in Vue.js
- Unit Testing with Vue Test Utils and Vitest
- Mocking Dependencies
- Testing Composables and Stores
- End-to-End Testing with Cypress
Module 9: Advanced Vue.js Concepts
- The Vue 3 Composition API in Depth: Composables and Logic Reuse
- Vue with TypeScript
- Render Functions and JSX
- Transitions and Animations
- Teleport, Suspense and Error Handling
- Server-Side Rendering (SSR) with Nuxt
- Performance Optimization
