Explain it simply
Template Syntax and Directives, in plain language
In a template, {{ value }} is text interpolation. To bind an HTML attribute to a reactive value, use v-bind or its shorthand :. Never render user input directly with v-html.
Problem → Why → Solution
The problem — why this concept matters
Using {{ }} inside an attribute
A common mistake
Rendering untrusted user input with v-html
Core concept — understand how it works
Learn the basics of Vue template syntax and directives, including interpolation, v-bind, and v-html.
- props or event
- component and template
- rendered Vue UI
Use {{ }} interpolation
Core syntax or pattern
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>Learn the basics of Vue template syntax and directives, including interpolation, v-bind, and v-html.
Read the code step by step
- props or event
<script setup>In a template, {{ value }} is text interpolation. To bind an HTML attribute to a reactive value, use v-bind or its shorthand :. Never render user input directly with v-html.
- component and template
</script>Learn the basics of Vue template syntax and directives, including interpolation, v-bind, and v-html.
- rendered Vue UI
</template>Apply Template Syntax and Directives in a small example and test normal, edge, and failure cases.
- props or event
- component and template
- rendered Vue UI
Success
Use {{ }} interpolation
Failure
Using {{ }} inside an attribute
Let's break it down simply
In a template, {{ value }} is text interpolation. To bind an HTML attribute to a reactive value, use v-bind or its shorthand :. Never render user input directly with v-html.
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>Su Su
[avatar image]
OnlineTry it yourself
Create a product object and display its title, price, and image src in the template.
Template Syntax — Vue.js
Real-world usage
How to apply it in a real project
Apply Template Syntax and Directives in a small example and test normal, edge, and failure cases.
Mini challenge
Build it yourself
Create a product object and display its title, price, and image src in the template.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
<script setup>
const profile = {
name: 'Su Su',
avatar: '/avatar.png',
active: true
}
</script>
<template>
<h2>{{ profile.name }}</h2>
<img :src="profile.avatar" :alt="profile.name">
<p :class="{ online: profile.active }">Online</p>
</template>Expected: Use {{ }} interpolation
Show hint
Apply Template Syntax and Directives in a small example and test normal, edge, and failure cases.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- props or event → component and template → rendered Vue UI
- Learn the basics of Vue template syntax and directives, including interpolation, v-bind, and v-html.
- Using {{ }} inside an attribute
- Apply Template Syntax and Directives in a small example and test normal, edge, and failure cases.
Template Syntax — Vue.js