vue实现计算平均分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算平均分</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<body>
<div align="center"> <p>计算平均分</p></div>
<div id="app" align="center">
<table border="2px">
<tr>
<td>数学</td>
<td><input type="text" v-model="math"></td>
</tr>
<tr>
<td>英语</td>
<td><input type="text" v-model="english"></td>
</tr>
<tr>
<td>语文</td>
<td><input type="text" v-model="chinese"></td>
</tr>
<tr>
<td>总分</td>
<td>{{sum}}</td>
</tr>
<tr>
<td>平均分</td>
<td>{{avaerage}}</td>
</tr>
</table>
</div>
</body>
<script>
new Vue({
el:"#app",
data:{
math:100,
english:100,
chinese:100,
},
computed:{
sum:function () {
return this.math+this.english+this.chinese ;
},
avaerage:function () {
return Math.round(this.sum/3);
}
}
});
</script>
</html>
如图所示: