Menu
CoddyTech

Text Interpolation

Part of the Fundamentals section of Coddy's Vue journey. Lesson 3 of 55.

An interpolation evaluates a JavaScript expression and displays the result as text. With the values below, the paragraph reads Tea: 8 cups. Dividing a number inside another interpolation uses the same expression rules as JavaScript.

const drink = 'Tea';
const cups = 8;
// Template: <p>{{ drink }}: {{ cups }} cups</p>
// Template: <small>{{ cups / 4 }} trays</small>

Top-level variables in <script setup> are available to the template without a separate export. Interpolation is for text content, not attribute values. Expressions produce a value; declarations such as const belong in the script block.

challenge icon

Challenge

Easy

Use the supplied event and seats variables to display Poetry night: 12 seats in p#result. Derive 6 pairs in p#pairs by dividing the seat count by two. Do not replace the variables with a single prewritten sentence.

Try it yourself

<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals