---
title: "Components — Splitting HTML | Progressive Vue"
description: "Split templates into components — like HTML custom elements"
last_updated: "2026-11-15"
canonical_url: "https://wtrclred.vercel.app/en/books/progressive-vue/05"
language: "en"
---

# Components — Splitting HTML | Progressive Vue

Turn on watercolor background effects. * May affect performance, battery life, and temperature on some devices.

### Table of Contents

- [The Template Is Getting Big](#the-template-is-getting-big)
- [What Is a Component?](#what-is-a-component)
- [Defining a Component](#defining-a-component)
- [props: Receiving Data from Parent](#props-receiving-data-from-parent)
- [emit: Child-to-Parent Communication](#emit-child-to-parent-communication)
- [Looking at the Root Template](#looking-at-the-root-template)
- [Summary](#summary)

## The Template Is Getting Big

 The Bookshelf app from the previous chapter has grown to a reasonable size.

The template includes cards, a search bar, and tag filters.

 As applications grow, writing everything in a single template becomes painful.

Even with plain HTML, you'd want to split by section.

 In Vue, you can extract parts of a template into components .

## What Is a Component?

 A component is like defining your own HTML tag .

 HTML has built-in elements like ` `, ` `, ` `.

With components, you can create your own elements like ` ` or ` `.

 

```html
  <!-- This is the goal --> 
 <  div   id  =  "app"  > 
   <  h1  > My Bookshelf <  /  h1  > 
   <  search-bar  >  <  /  search-bar  > 
   <  tag-filter  >  <  /  tag-filter  > 
   <  book-card   v-for  =  "book in filteredBooks"   :book  =  "book"  >  <  /  book-card  > 
 <  /  div  >
```

 Similar to HTML Custom Elements (Web Components).

Just write ` ` in the template, and its content expands.

## Defining a Component

 In a CDN environment, register components with `app.component()`.

Inside `setup()`, receive `props` and return values for the template.

 

```javascript
  app  .  component  (  "book-card"  ,   { 
   props  :   [  "book"  ]  , 
   setup  (  props  )   { 
     return   {   book  :   props  .  book   }  ; 
   }  , 
   template  :   `
    <div class="card">
      <h2>{{ book.title }}</h2>
      <p>{{ book.description }}</p>
      <span class="tag" v-for="tag in book.tags">
        {{ tag }}
      </span>
    </div>
  `  , 
 }  )  ;
```

 Notice the `template` content.

It's exactly the card HTML from the previous chapter, moved as-is.

### props : Receiving Data from Parent

 `props: ['book']` declares that this component receives `book` data from outside.

The `props` received in `setup(props)` are reactive — when parent data changes, the component updates automatically.

 

```html
  <  book-card   :book  =  "book"  >  <  /  book-card  >
```

 `:book="book"` — that's `v-bind`. Passing parent data to the child.

Written as an HTML attribute, as always.

## emit : Child-to-Parent Communication

 Data flow between components is one-directional.

- Parent → Child : props ( :book="book" )

- Child → Parent : emit ( @select="toggleTag" )

 Look at the `search-bar` component's `setup()`.

 

```javascript
  setup  (  props  ,   {   emit   }  )   { 
   const   onInput   =   (  e  )   =  >   emit  (  'update:query'  ,   e  .  target  .  value  ) 
   return   {   query  :   props  .  query  ,   onInput   } 
 }
```

 `emit` is received from `setup()`'s second argument.

On each input, it fires an `update:query` event, and the parent catches it to update `searchQuery`.

Same concept as HTML's event model (`addEventListener` / `dispatchEvent`).

## Looking at the Root Template

 With components, the root template becomes:

 

```html
  <  h1  > My Bookshelf <  /  h1  > 
 <  search-bar   :query  =  "searchQuery"   @update:query  =  "searchQuery = $event"  >  <  /  search-bar  > 
 <  tag-filter   :tags  =  "allTags"   :selected  =  "selectedTag"   @select  =  "toggleTag"  >  <  /  tag-filter  > 
 <  book-card   v-for  =  "book in filteredBooks"   :book  =  "book"  >  <  /  book-card  >
```

 It reads like HTML custom elements .

The app structure is clear at a glance: search bar, tag filter, book cards.

 Each component's template is also HTML .

Looking inside a component, you can immediately see what it renders.

## Summary

- Components are like HTML custom elements

- props receive data from parent — passed as HTML attributes

- setup(props, { emit }) receives props and emit

- emit sends events from child to parent — same as HTML's event model

- Even split into components, each part remains HTML

- App structure is readable from the template

- Still just a single index.html file (but in the next chapter...)

 [← Previous Reactivity — From Static to Dynamic](/en/books/progressive-vue/04)

 [Next → The Full Picture of Progressive](/en/books/progressive-vue/06)

### Related

- [Signals and Signals. And Retained UI.](/en/posts/12) #javascript #oss #signals
- [Characterize Vue.js](/en/posts/07) #vue #javascript #oss
- [Vue.js is not Easy. It is Approachable.](/en/posts/06) #vue #javascript #language
- [What is Vue.js? It's just a language lol](/en/posts/05) #vue #javascript #language
- book [Progressive Vue](/en/books/progressive-vue) #vue #frontend #progressive
- chapter [Bringing in Vue via CDN](/en/books/progressive-vue/02) #vue #cdn #esm

[← Back to book](/en/books/progressive-vue)

## Sitemap

- [Browse every page on wtrclred](https://wtrclred.vercel.app/sitemap.md)
