Vuejs Course

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>

var vm = new Vue({
 el: '#app',
 data: {str: 'Be Yourself.'}

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.
<div id='app'>
<p>Using mustaches: {{ str_html }}</p>
<p>Using v-html directive: <span v-html="str_html"></span></p>

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

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>

var vm = new Vue({
 el: '#app',
 data: {nr: 0}
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'>

var vue_ob = new Vue({
 el: '#app',
 data: {msg: 'Hello Vue!'}

Daily Test with Code Example

What attribute makes the input text box to not be modified by the user?
checked="checked" readonly="readonly" disabled="disabled"
<input type="text" value="fixed-value" readonly="readonly" name="a_name" />
What CSS property allows you to create rounded corners in your webpage design?
background-size border-size border-radius
.class {
  border:2px solid blue;
What instruction displays a confirmation dialog box to the viewer, who must then click OK or Cancel to proceed?
indexOf() confirm() prompt()
var ques = window.confirm("The result of 0+0 is 0?");
if (ques) alert("Corect");
else alert("Incorrect");
Indicate the PHP function that returns the lowest number of the parameter values.
floor() ceil() min()
$min_nr = min(12, 8, 25, 13);
echo $min_nr;        // 8
Template Syntax

Last accessed pages

  1. PHP Unzipper - Extract Zip, Rar Archives (20215)
  2. jQuery ajax() method (16508)
  3. Node.js Move and Copy Directory (15808)
  4. SHA512 Encrypt hash in JavaScript (21233)
  5. Read Excel file data in PHP - PhpExcelReader (90389)

Popular pages this month

  1. PHP Unzipper - Extract Zip, Rar Archives (96)
  2. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (58)
  3. JavaScript Course - Free lessons (45)
  4. SHA1 Encrypt data in JavaScript (44)
  5. Read Excel file data in PHP - PhpExcelReader (40)