elementplus table两列一个表头
时间: 2024-06-26 13:01:38 浏览: 8
Element Plus 是 Vue 3 时代的 UI 组件库,它基于 Element UI 进行了升级和优化。在 Element Plus 中,Table 组件是一个常用的用于展示数据列表的组件,它支持多列布局,包括一个表头区域和若干列的数据内容。
在 Element Plus 的 Table 组件中,你可以通过 `el-table-column` 标签来定义每一列,包括表头(th)和数据列(td)。这里是一个基础的例子,展示了如何创建一个包含两列的表头:
```html
<template>
<el-table :data="tableData">
<el-table-column
prop="name" // 属性名,对应数据中的字段
label="Name" // 表头文字
width="180" // 列宽,可选
/>
<el-table-column
prop="age" // 另一属性名
label="Age" // 另一表头文字
width="180" // 列宽
/>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 },
{ name: 'Mike', age: 35 }
]
};
}
};
</script>
```
在上面的代码中,`prop` 属性定义了数据中用来显示的字段,`label` 属性定义了表头的文字内容。每个 `<el-table-column>` 都对应表格的一列。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)