Vue.js is a library that builds a data-driven Web interface. Its goal is to implement the data binding and the combined view components of the response through the simplest possible API, and today we start vue.js learning.
The installation and use of Vue
One, Vue's: Http://vuejs.org/js/vue.js
Second, the first example of Vue:
The structure of the project is as follows, introducing Vue.js
Vue1.html's Code:
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Vue1</title> <Scripttype= "Text/javascript"src=".. /vue.js "></Script></Head><Body> <DivID= "App"> <P>{{Message}}</P> <inputtype= "text"name= "message"V-model= "message" /> </Div> <Scripttype= "Text/javascript"src= "Js/vue1.js"></Script></Body></HTML>
Vue1.js's Code:
var New Vue ({ ' #app ', data: { "Hello World" }});
The effect of the operation is as follows:
Attention:
- El: ' #app ' is the part that manages the ID for the app.
- The introduction of Vue1.js is behind the page code, otherwise there will be errors in some browsers where #app elements cannot be found.
Simple use of Vue
All of the examples below are based on the above examples. Write only the added code here
One, the rendering of the list: the use of v-for
Add the following code to the <div id= "app" >:
<ul> <li vfor = ' person in persons ' > {{person.name}} loves {{person.love}} </li></ul>
Add the following code to the Vue1.js data:
persons: [ ' Huhx ', Love: ' Code '}, ' Chenhui ', Love: ' book '}]
The results are as follows:
Second, processing input: the use of V-on:click
Add the following code to the <div id= "app" >:
<v-on:click= "changecontent (' Huhx ')">click on! </ Button >
Add the following code to the Vue1.js:
methods: { function(element) { this. Message = ' I love '+ element; }}
Friendship Link
- Vue's official tutorial: http://cn.vuejs.org/guide/index.html
- Vue's official api:http://cn.vuejs.org/api/
The use of VUE Foundation---->VUEJS (i)