有时el-table的默认样式不能满足我们的要求,需要我们修改它的样式来达到我们的需求
1、 默认的el-table表格
<template>
<el-table :data="tableData" border style="width: 100%">
<el-table-column prop="date" label="Date" width="180" />
<el-table-column prop="name" label="Name" width="180" />
<el-table-column prop="address" label="Address" width="250" />
</el-table>
</template>
<script setup>
const tableData = [
{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
},
{
date: '2016-05-02',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
},
{
date: '2016-05-04',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
},
{
date: '2016-05-01',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
}
]
</script>
<style lang="less" scoped></style>
2、表格内容样式
<el-table
:data="tableData"
border // 显示竖线边框
style="width: 100%; height: 100%; font-size: 15px; color: red; border-radius: 10px" // 设置表格整体样式
:header-cell-style="{ 'font-size': '20px', color: '#41b883' }" // 设置表头样式
:row-style="{ height: '60px' }" // 设置tbody的行高
:cell-style="{ padding: '30px 0' }" // 设置tbody的行间距
>
3、去掉竖线边框
<el-table
:data="tableData"
// 删除border
style="width: 100%; height: 100%; font-size: 15px; color: red; border-radius: 10px"
:header-cell-style="{ 'font-size': '20px', color: '#41b883' }"
:row-style="{ height: '60px' }"
:cell-style="{ padding: '30px 0' }"
>
4、去掉所有边框
<el-table
:data="tableData"
border
style="width: 100%;
height: 100%;
font-size: 15px;
color: red;
--el-table-border-color: none" // 去掉表格所有边框
:header-cell-style="{ 'font-size': '20px', color: '#41b883' }"
:row-style="{ height: '60px' }"
:cell-style="{ padding: '30px 0' }"
>
5、对边框某一边单独操作
这部分,可以F12打开开发者工具,去进行调试,找到该样式,去强制修改成自己的样式即可