Your First Vue Component
A component is one reusable block of a web page. A Vue page is made from one or more components.
A component file
This file holds one heading.
<template>
<h1>Hello, Vue!</h1>
</template>Two lines in one component
One component can hold more than one line.
<template>
<div>
<h1>Vue Greeting</h1>
<p>Hello from a component.</p>
</div>
</template>Example
<template>
<div>
<h1>Hello from a component</h1>
<p>This line comes from the same component.</p>
</div>
</template>Key points
- A component is one reusable block of a web page.
- Markup is the HTML that shapes a page.
- Each component holds its own markup.
- A page can hold many components at once.
In this example, one component holds a heading and a line. The heading reads Hello from a component. The line reads This line comes from the same component. The component keeps both pieces together.
Note
This lesson uses a template-only component. It holds markup and nothing else.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is a Vue component?