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>
</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 meta tag provides a short description of the page?
<meta content="..."> <meta description="..."> <meta http-equiv="...">
<meta name="description" content="70-160 characters that describes the content of the page" />
Which CSS property is used to stop the wrapping effect of the "float"?
clear text-align position
#some_id {
  clear: both;
}
Click on the method which gets an array with all the elements in the document that have a specified tag name.
getElementsByName() getElementById() getElementsByTagName()
var divs = document.getElementsByTagName("div");
var nr_divs = divs.length;
alert(nr_divs);
Indicate the PHP function which returns the number of elements in array.
is_[) count() strlen()
$arr =[7, 8, "abc", 10);
$nri = count($arr);
echo $nri;        // 4
Template Syntax

Last accessed pages

  1. PHP Strings (3263)
  2. Selection Tools (8145)
  3. Get Lower, Higher, and Closest Number (5342)
  4. Simple Admin Login PHP Script (10894)
  5. jQuery parent, children and nth-child() (13826)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (201)
  2. Read Excel file data in PHP - PhpExcelReader (66)
  3. The Mastery of Love (56)
  4. PHP Unzipper - Extract Zip, Rar Archives (51)
  5. Working with MySQL Database (34)
Chat
Chat or leave a message for the other users
Full screenInchide