Vue3 Fundamentals · Rendering & Templates

Your first component

Single-file components

Your first component

A page is made of pieces: a heading, a paragraph, a button. Vue lets you describe one piece as a component, then render that component wherever you need it.

In Vue, a component lives in a single file — a single-file component. One file holds everything that piece needs, in up to three blocks:

  • <script setup> holds the component's logic and data.
  • <template> describes the markup the component renders.
  • <style> holds the component's styles.
<script setup>
const greeting = 'Hello, Vue!';
</script>

<template>
  <h1>{{ greeting }}</h1>
</template>

The <script setup> block runs once when the component is created. The <template> block turns its data into real DOM elements. The double braces, {{ greeting }}, show the value of greeting inside the heading.

The Test for this Lesson imports App from App.vue, mounts it, and inspects what it rendered. The component must be exported as the file's default export — which is exactly what <script setup> produces, so you never write export yourself.

The element you choose matters. A <p> and an <h1> look similar in source but are different roles in the accessibility tree. Your job is to render a level-one heading with the exact text the Challenge asks for.

Challenge

The page is showing a paragraph where a heading belongs. Turn that piece into a real heading: export an App component from App.vue whose template renders a level-one heading (<h1>) with the text Hello, Vue!.

The Test mounts your component and looks for a heading with that text. The starter renders a paragraph instead, so the Test fails. Change the element to a heading and keep the text.

App.vue
<script setup>
const greeting = 'Hello, Vue!';
</script>

<template>
  <p>{{ greeting }}</p>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.