1. Installation: use the script tag is introduced
<-! Development environment version includes a helpful warning command line ->
< Script src = "https://cdn.jsdelivr.net/npm/vue/dist/vue.js"> </ Script>
<-! Production version, optimized for size and speed -> <Script src = "https://cdn.jsdelivr.net/npm/vue"> </ Script>
2. Example
//HTML <div id="app"> {{ message }} </div> //JS var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' } })
HTML <div the above mentioned id = "App-2"> <span the bind-v: title = "the Message"> hover for a few seconds to view the message dynamic binding of here! </ span> </ div> the JS var = App2 new new Vue ({ EL: '# App2', Data: { Message:. 'page loaded' + new new a Date () toLocaleString () } })
HTML
<div the above mentioned id = "app3">
<the p-v-IF = "Seen"> Now you see me </ the p->
</ div>
JS
var = app3 new new Vue ({
EL: '# app3 ',
Data: {
Seen: to true
}
})
at the input console , you will find the message displayed before disappearing.app3.seen = false
The HTML
<div ID = "APP4">
<OL>
<-V for Li = "TODO in Todos">
{{}} todo.text
</ Li>
</ OL>
</ div>
the JS
var = new new APP4 VUE ({
EL: '# App-. 4',
Data: {
Todos: [
{text: 'learning the JavaScript'},
{text: 'learning VUE'},
{text: 'whole cow project'}
]
}
})
in console, enter , you will find a list of the last added a new project.app4.todos.push({ text: '新项目' })
Implement user and application interaction, we can add an event listener with v-on command the HTML <div ID = "App-. 5"> <P> {{Message}} </ P> <Button v-on: the Click = "reverseMessage"> reverse message </ Button> </ div> the JS var = APP5 new new Vue ({ EL: '# APP5', Data: { message: '! Vue.js the Hello' }, Methods: { reverseMessage : function () { this.message = this.message.split ( '') Reverse () the Join.. ( '') } } })
v-model instruction, it can easily form a two-way binding between input and application state. The HTML <div ID = "APP6"> <P> Message {} {} </ P> <INPUT = V-Model "Message"> </ div> the JS var = APP6 new new Vue ({ EL: '#app -6 ', Data: { Message:' Vue the Hello '! } })