<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="/pluins/Vue.js"></script>
<title>两个值变化相加</title>
</head>
<body>
<div id="box">
<input type="text" v-model="a" >
<input type="text" v-model="b" >
{{c}}
</div>
<script type="text/javascript">
new Vue({
el:'#box',
// template:'<h6 style="color:red;">asdfffff</h6>',
data:{
a:2,
b:1,
c:3
},
watch: {
a: function () {
this.c=parseInt(this.a)+parseInt(this.b)
},
b: function () {
this.c=parseInt(this.a)+parseInt(this.b)
}
}
});
</script>
</body>
</html>