Interpolation and Directives
Use mustache interpolation and core directives in templates.
Interpolation and Directives is a free Vue Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Template Syntax Overview
Vue templates are valid HTML enhanced with special syntax:
- Mustache interpolation for text
- Directives (v- prefixed attributes) for behavior
Vue compiles these into efficient render functions.
Mustache Interpolation
The double curly braces, or mustache syntax, output text.
The content is a JavaScript expression, not just a variable name.
<span>Hello, {{ userName }}</span>
<span>{{ price * quantity }}</span>
<span>{{ isActive ? "On" : "Off" }}</span>v-bind for Attributes
Mustaches do not work inside HTML attributes. Use v-bind to bind data to an attribute.
<a v-bind:href="profileUrl">Profile</a>
<img v-bind:src="imagePath" v-bind:alt="caption" />
<button v-bind:disabled="isLoading">Submit</button>v-bind Shorthand
v-bind is so common that it has a shorthand: just a colon.
<!-- Full syntax -->
<a v-bind:href="url">Link</a>
<!-- Shorthand -->
<a :href="url">Link</a>v-on for Events
The v-on directive listens for DOM events and runs handlers.
<button v-on:click="handleClick">Click me</button>
<input v-on:input="onType" />
<form v-on:submit="onSubmit">...</form>v-on Shorthand
v-on also has a shorthand: the at symbol.
<!-- Full syntax -->
<button v-on:click="save">Save</button>
<!-- Shorthand -->
<button @click="save">Save</button>Inline vs Method Handlers
Event handlers can be inline expressions or method names.
<!-- Inline expression -->
<button @click="count++">Add</button>
<!-- Method handler -->
<button @click="increment">Add</button>
<!-- Inline with the event object -->
<button @click="log($event)">Log</button>v-text
The v-text directive sets an element text content. It is equivalent to a mustache.
<!-- These two are equivalent -->
<span v-text="message"></span>
<span>{{ message }}</span>v-html
The v-html directive renders a string as real HTML, not escaped text.
<div v-html="rawHtml"></div>
<!-- If rawHtml = "<b>Bold</b>",
it renders actual bold text -->v-html and XSS Caution
Warning: v-html is dangerous with untrusted content.
- It can inject malicious scripts (XSS attacks)
- Only use it on content you fully trust
- Never render user-submitted HTML directly
For normal text, always prefer mustache interpolation, which escapes HTML.
Directive Arguments
Some directives take an argument after a colon, such as which attribute or event.
<!-- argument is the attribute name -->
<a :href="url">Link</a>
<!-- argument is the event name -->
<button @click="run">Run</button>
<!-- dynamic argument -->
<a :[attrName]="value">Dynamic</a>Quick Check
Test your understanding of interpolation and directives.
Recap: Interpolation and Directives
You learned Vue template basics:
- {{ }} mustache outputs text expressions
- v-bind (shorthand :) binds attributes
- v-on (shorthand @) handles events
- v-text sets text content
- v-html renders raw HTML (XSS risk, use carefully)
Next: conditionals and loops.
Frequently asked questions
Is the “Interpolation and Directives” lesson free?
Yes — the full text of “Interpolation and Directives” is free to read here on the web, and the Vue Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.
What will I learn in “Interpolation and Directives”?
Use mustache interpolation and core directives in templates. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vue Academy?
No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Interpolation and Directives” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vue Academy lesson?
Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Interpolation and Directives
- Conditionals and Loops
- Attribute and Class Bindings