定义一组能存储十个学生信息(学号,姓名,学成绩)的数组,使用vue循环遍历指令显示十个学生的信息
时间: 2024-02-09 14:07:12 浏览: 25
好的,这是一个简单的Vue.js的例子,可以用来展示十个学生的信息。我们首先需要定义一个学生信息数组,然后使用Vue.js的v-for指令循环遍历数组中的每一个学生信息,并将其显示出来。
```html
<template>
<div>
<h1>学生信息列表</h1>
<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: 1, name: '张三', score: 90 },
{ id: 2, name: '李四', score: 85 },
{ id: 3, name: '王五', score: 92 },
{ id: 4, name: '赵六', score: 80 },
{ id: 5, name: '孙七', score: 88 },
{ id: 6, name: '周八', score: 95 },
{ id: 7, name: '吴九', score: 87 },
{ id: 8, name: '郑十', score: 93 },
{ id: 9, name: '钱十一', score: 89 },
{ id: 10, name: '宋十二', score: 91 }
]
}
}
}
</script>
```
在这个例子中,我们定义了一个名为"students"的数组,其中包含了十个学生的信息。然后,我们使用v-for指令循环遍历这个数组中的每一个学生信息,并将它们以表格的形式显示出来。
注意,在v-for指令中,我们使用了"student"和"index"这两个变量来分别表示当前循环到的学生信息和它在数组中的索引值。同时,我们使用":key"属性来为每一个循环出来的学生信息指定一个唯一的key值,这样可以提高Vue.js的渲染效率。
希望这个例子能够帮助你了解如何使用Vue.js的v-for指令来循环遍历数组并显示其中的数据。