1. 指令综合案例-信息表
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>指令综合练习</title>
</head>
<style>
/* 90分以上 */
.active1 {
background-color: blue;
color: white;
}
/* 60分以下 */
.active2 {
background-color: red;
color: white;
}
</style>
<body>
<div id="app">
<!-- 1. 页面结构 -->
<!-- 添加表单 -->
<input placeholder="用户名" v-model="stuInfo.name">
<hr>
<input placeholder="电话" v-model="stuInfo.tel">
<hr>
<input placeholder="成绩" v-model="stuInfo.score">
<hr>
<button @click="addStudent">添加用户信息</button>
<hr>
<!-- 表单遍历用户的信息列表 -->
<table width="600" border="1" style="border-collapse: collapse;">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>电话</th>
<th>成绩</th>
<th>等级</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!-- 3. 遍历和渲染数据 -->
<tr
v-for="(item,index) in students"
:key="item.id"
:class="{ active1:item.score>=90,active2:item.score < 60 }"
>
<td>{
{item.id}}</td>
<td>{
{item.name}}</td>
<td>{
{item.tel}}</td>
<td>{
{item.score}}</td>
<td>
<span>优</span>
<span>良</span>
<span>中</span>
<span>差</span>
</td>
<td>
<button @click="deleteStu( index )">删除</button>
</td>
</tr>
<!-- <tr class="active1">
<td>111</td>
<td></td>
<td></td>
<td>95</td>
<td></td>
</tr>
<tr>
<td>111</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="active2">
<td>111</td>
<td></td>
<td></td>
<td>60</td>
<td></td>
</tr> -->
<tr v-if="students.length == 0">
<td colspan="5">暂无数据</td>
</tr>
</tbody>
</table>
<button @click="deleteAll">全部删除</button>
</div>
</body>
<script src="vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
//2. 初始化数据
students: [
{ id: 1, tel: '15811', name: '诸葛亮', sex: '男', score: 98 },
{ id: 2, tel: '15822', name: '周瑜', sex: '男', score: 88 },
{ id: 3, tel: '15833', name: '刘阿斗', sex: '男', score: 50 },