<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.boss {
width: 1000px;
height: 500px;
display: flex;
margin: 0 auto;
}
.box1 {
flex: 8;
height: 100%;
box-sizing: border-box;
padding: 50px;
}
.box2 {
flex: 4;
height: 100%;
box-sizing: border-box;
padding: 50px 0;
font-size: 20px;
}
.box2 input {
width: 200px;
height: 50px;
margin-bottom: 20px;
font-size: 16px;
}
button {
width: 70px;
height: 40px;
margin-left: 60px;
background-color: rgb(0,101,158);
color: #fff;
border-radius: 10px;
border: none;
}
</style>
</head>
<body>
<div id="app">
<div class="boss">
<div class="box1">
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center">
<tr style="background-color: rgb(245,245,245);border: none;" height="40px">
<th>编号</th>
<th>姓名</th>
<th>科目</th>
<th>成绩</th>
<th>操作</th>
</tr>
<tr style="text-align: center;border: none;" height="40px" v-for="(item,index) of arr">
<td>{{index+1}}</td>
<td>{{item.userName}}</td>
<td>{{item.km}}</td>
<td v-if="item.cj>=60">{{item.cj}}</td>
<td style="color: red;" v-if="item.cj<60">{{item.cj}}</td>
<td>
<div style="text-decoration: underline;cursor: pointer;" @click="sc(index)">删除</div>
</td>
</tr>
</table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center">
<tr style="text-align: center;border: none;" v-if="xs" height="40px">
<td style="border: none;text-align: right;">总分:</td>
<td style="border: none;text-align: left;padding-left: 20px;box-sizing: border-box;">{{zf}}</td>
<td style="border: none;text-align: right;">平均分:</td>
<td style="border: none;padding-left: 20px;box-sizing: border-box;text-align: left;">{{pjf}}</td>
<!-- <td style="border: none;"></td> -->
</tr>
</table>
</div>
<div class="box2">
姓名:<input type="text" v-model="obj.userName" placeholder="请输入姓名">
<br>
科目:<input type="text" v-model="obj.km" placeholder="请输入科目">
<br>
分数:<input type="text" v-model="obj.cj" placeholder="请输入分数">
<br>
<button @click="tj()">添加</button>
</div>
</div>
</div>
</body>
<script src="./vue.js"></script>
<script>
Vue.config.productionTip = false;
var vm = new Vue({
el:"#app",
data(){
return{
arr:[],
xs:true,
zf:"",
pjf:"",
arrs:[],
sum1:0,
ys:{},
obj:{
userName:"",
km:"",
cj:"",
},
}
},
methods:{
tj(){
this.arr.push(this.obj);
this.obj.cj=Number(this.obj.cj);
this.sum1+=this.obj.cj;
console.log(this.sum1);
this.zf=this.sum1;
this.pjf=(this.sum1/this.arr.length).toFixed(1);
this.obj={
userName:"",
km:"",
cj:""
}
if(this.pjf=="NaN"){
this.pjf=0;
}
},
sc(a){
console.log(this.arr[a].cj);
this.sum1-=this.arr[a].cj;
this.zf=this.sum1;
this.arr.splice(a,1)
this.pjf=(this.sum1/this.arr.length).toFixed(1);
if(this.pjf=="NaN"){
this.pjf=0;
}
}
}
})
</script>
</html>