Vue.js Quick Start Example Tutorials _javascript tips

Source: Internet
Author: User

What is Vue

Vue is the meaning of the French view, Vue.js is a lightweight, high-performance, modular MVVM Library with a very easy to access API.

I. BASIC structure

Index.html Code:

<script src= ". /vue.js "></script> 
<div id=" App "> 
{message}} 
</div> 
<script src=" App.js "></script> 
<!--Note: App.js is to be introduced at the end of the Div,vue to get the corresponding element before the ID is the app. Otherwise there will be an error: [Vue warn]: Cannot find element: #app-->

App.js Code:

New Vue ({ 
el: ' #app ',//Select part of data to use Vue: 
{//define array in which you can use {{}} to reference message 
: ' Hello vue.js! ' 
} 
})

Two, two-way data binding

Index.html Code:

<script src= ". /vue.js "></script> 
<div id=" app "> 
<p>{{message}}</p> 
<!--set up bidirectional data binding, V-model, the property value is the data to bind--> 
<input v-model= "message" > 
</div> 
<script src= "App.js" > </script>

App.js Code

New Vue ({ 
el: ' #app ', 
data: {message 
: ' Hello vue.js! ' 
} 
})

Third, rendering list

Index.html Code:

<script src= ". /vue.js "></script> 
<div id=" app "> 
<ul> 
<!--v-for for loop traversal--> 
<li V-for= "Todo in Todos" > 
{todo.text}} 
</li> 
</ul> 
</div> 
<script Src= "App.js" ></script>

App.js Code:

New Vue ({ 
el: ' #app ', data 
: { 
todos: [//define Todos data 
{text: ' Learn JavaScript '} in Data { 
text: ' Learn Vue.js '}, 
{text: ' Build Something Awesome '} 
} 
}

Iv. Handling User Input

Index.html Code:

<script src= ". /vue.js "></script> 
<div id=" app "> 
<p>{{message}}</p> 
<!-- Vue uses v-on: prefix to bind various event-triggered methods--> 
<button v-on:click= "Reversemessage" >reverse message</button> 
</div> 
<script src= "App.js" ></script>

App.js Code:

New Vue ({ 
el: ' #app ', 
data: { 
message: ' Hello vue.js! ' 
}, 
methods: {//methods field content to define the processing method 
reversemessage:function () { 
//This.message can change the value of the message data, which is reversed 
this.message = This.message.split ("). Reverse (). Join (')}} 
" 

The above is a small set to introduce the Vue.js QuickStart example tutorials, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.