el-table生成一个展示table没有表头
时间: 2023-10-07 07:06:18 浏览: 89
如果你想在 `el-table` 中隐藏表头,可以使用 `show-header` 属性并将其设置为 `false`。这将隐藏表头和表头行。
例如:
```html
<template>
<el-table :data="tableData" show-header="false">
<!-- 表格列 -->
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
</el-table>
</template>
```
在上面的示例中,`show-header` 属性被设置为 `false`,因此表头将被隐藏。请注意,如果您不需要表头行,请确保将其从表格中删除。
相关问题
el-table 动态生成表头和el-input
可以使用 v-for 指令动态生成 el-table 的表头,同时在表格中使用 el-input 组件。具体实现可以参考以下代码:
```html
<template>
<el-table :data="tableData">
<el-table-column v-for="(column, index) in tableColumns" :key="index" :prop="column.prop" :label="column.label">
<template slot-scope="scope">
<el-input v-model="scope.row[column.prop]"></el-input>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableColumns: [
{ label: '姓名', prop: 'name' },
{ label: '年龄', prop: 'age' },
{ label: '性别', prop: 'gender' }
],
tableData: [
{ name: '张三', age: 18, gender: '男' },
{ name: '李四', age: 20, gender: '女' },
{ name: '王五', age: 22, gender: '男' }
]
}
}
}
</script>
```
在上面的代码中,我们使用 v-for 指令遍历 tableColumns 数组,动态生成表头。同时,在 el-table-column 的模板中使用 el-input 组件,实现表格中的输入框。
el-table 表头最后一个取消右边框
可以通过 `::after` 伪元素来取消 el-table 表头最后一个单元格的右边框,具体方法如下:
1. 给 el-table 组件添加一个 class 名称,比如 `my-table`。
2. 使用 CSS 选择器 `.my-table .el-table__header th:last-child::after` 来选中 el-table 表头最后一个单元格的右边框。
3. 将 `border-right: none` 设置给选中的元素即可。
以下是示例代码:
```css
.my-table .el-table__header th:last-child::after {
content: "";
display: block;
position: absolute;
top: 0;
right: 0;
height: 100%;
border-right: none;
}
```
需要注意的是,这种方法只能用于取消表头最后一个单元格的右边框,如果要取消其他位置的边框,需要根据具体情况进行调整。