# Template Syntax

3F Design is built using Vue.js (opens new window).

Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying Vue instance's data. All Vue.js templates are valid HTML that can be parsed by spec-compliant browsers and HTML parsers.

Under the hood, Vue compiles the templates into Virtual DOM render functions. Combined with the reactivity system, Vue is able to intelligently figure out the minimal number of components to re-render and apply the minimal amount of DOM manipulations when the app state changes.

# Interpolations

# Text

The most basic form of data binding is text interpolation using the "Mustache" syntax (double curly braces):

<span>Message: {{ msg }}</span>
1

The mustache tag will be replaced with the value of the msg property on the corresponding data object. It will also be updated whenever the data object's msg property changes.

# Directives

Directives are special attributes with the v- prefix. Directive attribute values are expected to be a single JavaScript expression. A directive's job is to reactively apply side effects to the DOM when the value of its expression changes. Let's review the example we saw in the introduction:

<p v-if="seen">Now you see me</p>
1

Here, the v-if directive would remove/insert the <p> element based on the truthiness of the value of the expression seen.

# Arguments

Some directives can take an "argument", denoted by a colon after the directive name. For example, the v-bind directive is used to reactively update an HTML attribute:

<a v-bind:href="url"> ... </a>
1

Here href is the argument, which tells the v-bind directive to bind the element's href attribute to the value of the expression url.

Another example is the v-on directive, which listens to DOM events:

<a v-on:click="doSomething"> ... </a>
1

Here the argument is the event name to listen to. We will talk about event handling in more detail too.

# Shorthands

The v- prefix serves as a visual cue for identifying Vue-specific attributes in your templates. This is useful when you are using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used directives. At the same time, the need for the v- prefix becomes less important when you are building a SPA (opens new window), where Vue manages every template. Therefore, Vue provides special shorthands for two of the most often used directives, v-bind and v-on:

# v-bind Shorthand

<!-- full syntax -->
<a v-bind:href="url"> ... </a>

<!-- shorthand -->
<a :href="url"> ... </a>

<!-- shorthand with dynamic argument (2.6.0+) -->
<a :[key]="url"> ... </a>
1
2
3
4
5
6
7
8

# v-on Shorthand

<!-- full syntax -->
<a v-on:click="doSomething"> ... </a>

<!-- shorthand -->
<a @click="doSomething"> ... </a>

<!-- shorthand with dynamic argument (2.6.0+) -->
<a @[event]="doSomething"> ... </a>
1
2
3
4
5
6
7
8

They may look a bit different from normal HTML, but : and @ are valid characters for attribute names and all Vue-supported browsers can parse it correctly. In addition, they do not appear in the final rendered markup. The shorthand syntax is totally optional, but you will likely appreciate it when you learn more about its usage later.

# Official documentation

The official documentation for Vue.js can be found here: https://vuejs.org/v2/guide/ (opens new window).