1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| var app=Vue.createApp({ data(){ return{ isAverageThree:false, isScoreAverage:false, averageThreeCourse:0, infoScoreTotal:0, students:[{ stuName:"张三", stuID:22303, scoreOne:61, scoreTwo:66, scoreThree:79, scoreTotal:0, scoreAverage:0 }, { stuName:"李四", stuID:22304, scoreOne:86, scoreTwo:77, scoreThree:99, scoreTotal:0, scoreAverage:0 }, { stuName:"王五", stuID:22305, scoreOne:92, scoreTwo:99, scoreThree:89, scoreTotal:0, scoreAverage:0 } ], newStudent:{ stuName:"", stuID:0, scoreOne:0, scoreTwo:0, scoreThree:0, } } }, computed:{ meAverageThreeCourse(){ let total=0; for(let i=0;i<this.students.length;i++){ total+=this.students[i].scoreThree; } return total/this.students.length; }, }, methods:{ createNewStudent(){ if (this.newStudent.stuName === ''){ alert("学生姓名不能为空!"); return; }else if (this.newStudent.stuID === '' || this.newStudent.stuID == 0){ alert("学生学号格式不正确!"); return; }else if(this.newStudent.scoreOne<0 || this.newStudent.scoreOne>100){ alert("课程一(HTML5应用开发)成绩输入有误,成绩区间[0-100]!"); return; }else if(this.newStudent.scoreTwo<0 || this.newStudent.scoreTwo>100){ alert("课程二(JavaScript程序设计)成绩输入有误,成绩区间[0-100]!"); return; }else if(this.newStudent.scoreThree<0 || this.newStudent.scoreThree>100){ alert("课程三(前端框架(Vue.js)应用开发)成绩输入有误,成绩区间[0-100]!"); return; } else { this.students.push(this.newStudent); this.newStudent={ stuName:'', stuID:0, scoreOne:0, scoreTwo:0, scoreThree:0, } } }, deleteStudent(index){ this.students.splice(index,1); }, sortScoreThree(){ this.students.sort(function (a,b) { return b.scoreThree-a.scoreThree; }) }, averageThree() { this.isAverageThree = !this.isAverageThree; if (this.isAverageThree) { this.averageThreeCourse = this.meAverageThreeCourse; }else { this.averageThreeCourse = 0; } }, averageTotal() { this.isScoreAverage = !this.isScoreAverage; if (this.isScoreAverage) { for(let i=0;i<this.students.length;i++){ this.students[i].scoreAverage=(this.students[i].scoreOne+this.students[i].scoreTwo+this.students[i].scoreThree)/3; this.students[i].scoreAverage=this.students[i].scoreAverage.toFixed(0); } }else { for(let i=0;i<this.students.length;i++){ this.students[i].scoreAverage=0; } } }, scoreTotal(index){ return this.students[index].scoreOne+this.students[index].scoreTwo+this.students[index].scoreThree; }, filteredStudents() { if (this.search === '') { alert('请输入学生姓名!'); return; } else { for (let i = 0; i < this.students.length; i++) { if (this.students[i].stuName === this.search) { let stuSearch = []; stuSearch.push(this.students[i]); this.students = stuSearch; return; } } alert('没有该学生!'); } } }, }).mount("#app");
|