Vue3 Fundamentals · Rendering & Templates

Text interpolation

Text interpolation

You have a value in your component and you want it on the page. Hard-coding the value into the markup works until the value changes — then the page is stale.

Vue shows a value with text interpolation: a pair of double braces around an expression in the template.

<script setup>
const name = 'Vue';
</script>

<template>
  <p>Hello, {{ name }}!</p>
</template>

The braces mark the spot where Vue substitutes the value. The text around them stays as written, so the paragraph renders Hello, Vue!.

Anything that produces a value can go inside the braces — a variable, arithmetic, or a function call:

<p>{{ 2 + 2 }}</p>

That renders 4. Without the braces, <p>2 + 2</p> renders the literal characters 2 + 2, because the template treats plain text as text.

The braces only work in the template's text content. Inside an attribute they are read as ordinary characters, which is why attributes need a different tool — the next Lesson.

Your job is to interpolate a value instead of printing its name.

Challenge

A paragraph is supposed to greet the reader by name, but it prints the word name instead. Export an App component from App.vue whose template interpolates the name value, so the paragraph reads Hello, Vue!.

The Test mounts your component and reads the paragraph's text. The starter writes name as plain text, so the Test fails — wrap the value in double braces so Vue substitutes it.

App.vue
<script setup>
const name = 'Vue';
</script>

<template>
  <p>Hello, name!</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.