v-model数据绑定底层原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="app"> <div>{{msg}}</div>
//分行显示 <input type="text" v-bind:value="msg" v-on:input="handle">
//一行显示 <input type="text" v-bind:value="msg" v-on:input=msg=$event.target.value>
//v-model方式
<input type="text" v-model="msg">
</div>
<script src="./js/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
msg: 'hello'
},
methods: {
handle: function(event) {
this.msg = event.target.value;
}
}
})
</script>
</body>
</html>