<template>
<div>
<table>
<thead>
<tr>
<th v-for="(header, index) in headers" :key="index">{{ header }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, rowIndex) in tableData" :key="rowIndex">
<td v-for="(cell, cellIndex) in row" :key="cellIndex">{{ cell }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
data() {
return {
headers: ['姓名', '年龄', '职业'],
tableData: [
['张三', 25, '工程师'],
['李四', 30, '设计师'],
['王五', 28, '产品经理']
]
};
}
};
</script>
<style scoped>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
</style>
模板部分 (<template>):
<table> 标签来创建一个表格。v-for 指令遍历 headers 数组,动态生成表头内容。v-for 指令遍历 tableData 数组,动态生成表格行和单元格内容。脚本部分 (<script>):
data 函数返回组件的状态,包括 headers 和 tableData。headers 是一个数组,包含表格的表头信息。tableData 是一个二维数组,每一项代表表格中的一行数据。样式部分 (<style scoped>):
上一篇:vue 入门
下一篇:electron+vue
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站