定义一组能存储十个学生信息(学号,姓名,学成绩)的数组,使用vue循环遍历指令显示十个学生的信息
时间: 2024-02-06 14:11:36 浏览: 128
好的,以下是一个示例代码:
```html
<template>
<div>
<table>
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>成绩</th>
</tr>
</thead>
<tbody>
<tr v-for="(student, index) in students" :key="index">
<td>{{ student.id }}</td>
<td>{{ student.name }}</td>
<td>{{ student.score }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
data() {
return {
students: [
{ id: '001', name: '张三', score: 90 },
{ id: '002', name: '李四', score: 88 },
{ id: '003', name: '王五', score: 92 },
{ id: '004', name: '赵六', score: 85 },
{ id: '005', name: '钱七', score: 89 },
{ id: '006', name: '孙八', score: 91 },
{ id: '007', name: '周九', score: 87 },
{ id: '008', name: '吴十', score: 93 },
{ id: '009', name: '郑十一', score: 86 },
{ id: '010', name: '冯十二', score: 94 },
],
};
},
};
</script>
```
在这个示例中,我们定义了一个名为 `students` 的数组,其中存储了十个学生的信息。在模板中,我们使用了 `v-for` 指令来循环遍历这个数组,并将其中每个学生的信息显示在表格中。在每次循环中,我们使用 `:key` 属性来标识每个表格行的唯一性,以便 Vue 能够高效地更新 DOM。
阅读全文
相关推荐


















