Vue两个数字相加双向绑定
哥特2019-04-29 15:14:17600<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue两个数字相加</title>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.common.dev.js"></script>
</head>
<body>
<div id="box"> 请输入数字x:
<input type="text" v-model.number="x">
<br>
请输入数字y:
<input type="text" v-model.number="y">
<br>
当前x的值:
<p>{{x}}</p>
当前y的值:
<p>{{y}}</p>
合计是:
<p :style="red">{{total}}</p>
</div>
<script>
new Vue({
//设置挂载点
el: '#box',
data: {
x: '',
y: '',
red: 'color:red'
},
computed: {
total: function () {
return (this.x + this.y);
}
}
})
</script>
</body>
</html>