<script src='//cdn.jsdelivr.net/npm/vue'></script>- Or, you can copy the JavaScript code from that address, save it into a .js file on your server, then include that file in your page.
Vue js use a template syntax with double braces {{ }} as place-holders for data, that is linked to the DOM.
With Vue.js you can extend HTML with HTML attributes called directives. They are HTML attributes with the prefix v-, and offers functionality to HTML applications.
Vue.js provides built-in directives and user defined directives.
new Vue()
. A property el: binds the new Vue object to the HTML element with the ID added to el:.<div id='app'> <h1>{{ message }}</h1> </div> <script> var vue_ob = new Vue({ el: '#app', data: {message: 'Hello Vue!'} }) </script>
When a Vue object is bound to an HTML element, the HTML element will change when the Vue object changes:
<div id='app'> {{ message }} </div> <button id='btn'>Click</button> <script> var vue_ob = new Vue({ el: '#app', data: {message: 'Hello Vue!'} }) //When click on the #btn element, change message text document.getElementById('btn').addEventListener('click', (ev)=>{ vue_ob.message ='MarPlo - CoursesWeb'; }); </script>
v-model
directive binds the value of HTML elements to application data.
<div id='app'> <p>{{ msg }}</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>
v-for
directive you can bind an array of Vue objects to an "array" of HTML element; for example to create a list (LI):
<div id='app'> List created with Vue JS. <ul> <li v-for='li in list'>{{ li }}</li> </ul> </div> <script> var vue_ob = new Vue({ el: '#app', data: { list: ['Learn JavaScript', 'Learn Vue.js', 'Build Something Awesome'] } }) </script>
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net