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
EasyUse 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>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks