Vue Academy · Lesson

Interpolation and Directives

Use mustache interpolation and core directives in templates.

Lesson 1 of 313 steps

Interpolation and Directives is a free Vue Academy lesson on CoddyKit. This is lesson 1 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 3 lessons in total.

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.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “Interpolation and Directives” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “Interpolation and Directives”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 3 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.

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

  1. Interpolation and Directives
  2. Conditionals and Loops
  3. Attribute and Class Bindings
← Back to Vue Academy