Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the Vue instance's data. The templates are compiled into Virtual DOM render functions.
The most basic form of template is text interpolation using the "Mustache" syntax (double curly braces):
<div>Message: {{ msg }}</div>

The mustache tag will be replaced with the value of the msg property from the data object. It will also be updated whenever the value of the "msg" property changes.

- Example, when click on a button it sets a value o a data Vue property (here "str"), changing the text displayed into a Div:
<div id='app'>
<div>{{ str }}</div>
<button @click='str = "Love the Life"'>Click</button>
</div>

<script>
var vm = new Vue({
 el: '#app',
 data: {str: 'Be Yourself.'}
})
</script>

HTML tags in template

The double mustaches interprets the data as plain text. To output real HTML, you will need to use the v-html directive.
Example:
<div id='app'>
<p>Using mustaches: {{ str_html }}</p>
<p>Using v-html directive: <span v-html="str_html"></span></p>
</div>

<script>
var vm = new Vue({
 el: '#app',
 data: {str_html: '<b style="color:#00f">Be Yourself.</b>'}
})
</script>

Mustaches cannot be used inside HTML attributes.


Using JavaScript Expressions in Vue Template

Vue.js supports JavaScript expressions inside all data bindings (one single expression):
{{ number + 1 }}

{{ ok ? 'YES' : 'NO' }}

{{ message.split('').reverse().join('') }}

<div v-bind:id="'list-' + id"></div>
- Example, shows the number of clicks on a button:
<div id='app'>
<div>Number of licks: {{ nr}}</div>
<button @click='nr +=1'>Click</button>
</div>

<script>
var vm = new Vue({
 el: '#app',
 data: {nr: 0}
})
</script>
Another example, display in reverse order the characters added into an input text field:
<div id='app'>
 <p>{{ msg.split('').reverse().join('') }}</p>
 Add some text in this input:<br>
 <input v-model='msg'>
</div>

<script>
var vue_ob = new Vue({
 el: '#app',
 data: {msg: 'Hello Vue!'}
})
</script>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
Template Syntax

Last accessed pages

  1. Contact page - CoursesWeb (33629)
  2. Tabs effect with CSS (34283)
  3. Making DIV Contents Scroll Horizontally, with multiple Div`s inside (41086)
  4. Select the Content of HTML Element (3166)
  5. Insert, Select and Update NULL value in MySQL (48007)

Popular pages this month

  1. Making DIV Contents Scroll Horizontally, with multiple Div`s inside (2140)
  2. Contact page - CoursesWeb (2074)
  3. Tabs effect with CSS (2074)
  4. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (677)
  5. Insert, Select and Update NULL value in MySQL (537)