两个vue整数相加 结果自动更新
<script>
new Vue({
el:"#id",
data:{
onename:"",
twoname:"",
sum:"",
},
watch:{
onename:function () {
if(this.twoname.length==0){
this.sum='';
}else{
this.sum=Number(this.onename)+Number(this.twoname);
}
},
twoname:function () {
if (this.onename.length==0){
this.sum='';
}else{
this.sum=Number(this.twoname)+Number(this.onename);
}
}
}
})
</script>