VUE生成动态表格

<!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 scoped>
        table {
         border-collapse: collapse;
         width: 100%;
         margin-top: 20px;
         border-radius: 10px;
         overflow: hidden;
        }
        th {
         background-color: #076aac;
         color: #fff;
         font-weight: bold;
         padding: 8px;
         text-align: left;
         border: 1px solid #ffffff;
        }
        td {
         background-color: #f8f8f8;
         color: #333;
         padding: 8px;
         border: 1px solid #50a5f4;
        }
        .even-row {
        background-color: #fff;
        }
        .odd-row {
        background-color: #f2f2f2;
        }
        div {
         padding: 20px;
        }
        h1 {
         color: #ffffffbe;
         text-align: center;
         background: linear-gradient(200deg, #97b8ef, #07579c);
         border-radius: 10px;
         margin: 0 auto;
         max-width: 50%;
         padding: 10px;
        margin-bottom: 20px;
        }
   </style>
   <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <h1>学生信息管理</h1> <button @click="getstudents">获取</button>
        <table v-if="dataFetched">
             <thead>
                  <tr>
                       <th>序号</th>
                       <th>姓名</th>
                       <th>学号</th>
                       <th>性别</th>
                       <th>年级</th>
                       <th>专业</th>
                       <th>住址</th>
                       <th>省份</th>
                       <th>电话</th>
                  </tr>
             </thead>
             <tbody>
                <tr v-for="student in students">
                    <td>{{student.stuid}}</td>
                    <td>{{student.stuname}}</td>
                    <td>{{student.stuno}}</td>
                    <td>{{student.stugender}}</td>
                    <td>{{student.stugrade}}</td>
                    <td>{{student.stumajor}}</td>
                    <td>{{student.stuaddress}}</td>
                    <td>{{student.stunative}}</td>
                    <td>{{student.stuphone}}</td>
                </tr>
             </tbody>
        </table>
        </div>        
</body>
<script>
new Vue({
  el: '#app',
  data: {
    dataFetched:false,
    students:[]
  },
  methods: {
    getstudents(){
        setTimeout(()=>{
            const data=[{stuid:1,stuname:"张张",stuphone:13555555555,stugender:"女",stugrade:2021,stumajor:"软件工程",stuaddress:"成都市新都区",stunative:"四川省",stuno:20213100000},
                {stuid:1,stuname:"李李",stuphone:13888888888,stugender:"男",stugrade:2021,stumajor:"网络空间安全",stuaddress:"成都市新都区",stunative:"四川省",stuno:2021311111},
                {stuid:1,stuname:"王王",stuphone:13777777777,stugender:"女",stugrade:2021,stumajor:"计算机科学与技术",stuaddress:"成都市新都区",stunative:"四川省",stuno:20213122222}];
            this.students=data;
            this.dataFetched=true;
        },1000);
    }
  },
})


</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值