vue.js 监听属性watch
<!DOCTYPE html><html><head><meta charset="utf-8"><title>监听属性</title><script src="js/vue.js" type="text/javascript" charset="utf-8"></script>...
·
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>监听属性</title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="div1">
人民币<input type="number" v-model.number="a1"/>
汇率<input type="number" v-model.number="a2"/>
美元<input type="number" v-model.number="a3"/>
</div>
</body>
<script>
new Vue({
el: '#div1',
data: {
a1 : 1,//人民币为1
a2 : 0,//汇率为0
a3 : 0,//美元为0
},
watch:{
a1:function(val){
this.a1=val;
this.a3=this.a1 / this.a2;
},
a3:function(val){
this.a3=val;
this.a1=this.a3 * this.a2;
}
}
});
</script>
</html>
详细请看:how2java
更多推荐
已为社区贡献1条内容
所有评论(0)