双向数据绑定
样例:v-model
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<div>{{msg}}</div>
<div>
<input type="text" v-model="msg">
</div>
</div>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
data:{
msg: "hello world"
}
})
</script>
</body>
</html>
事件绑定
v-on
样例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<div>{{num}}</div>
<div>
<button type="button" v-on:click="num++">点击</button>
</div>
</div>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
data:{
num: 0
}
})
</script>
</body>
</html>
事件绑定方式:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<div>{{num}}</div>
<div>
<button type="button" v-on:click="handle">点击</button>
</div>
</div>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
data:{
num: 0
},
methods:{
handle: function(){
this.num++
}
}
})
</script>
</body>
</html>