vue+scss+element-ui实现表格表头斜杠一分为三方式
作者:A1203228440
这篇文章主要介绍了vue+scss+element-ui实现表格表头斜杠一分为三方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
vue+scss+element-ui表格表头斜杠一分为三
看了网上很多博客,大部分都是表头第一个斜线一份为2的样式,今天写一个样式一分为3的样式,可以根据项目情况适当增加或减少分割

<template>
<div>
<el-table :data="tableData" border style="width: 100%">
<el-table-column
:resizable="false"
class-name="column-custom"
prop="date"
label="日期"
width="120"
>
<template slot="header" slot-scope="scope">
<div class="header-div">
<div class="header-col1">区域</div>
<div class="header-col2">类型</div>
<div class="header-col3">水量</div>
<div class="header-line1"></div>
<div class="header-line2"></div>
</div>
</template>
</el-table-column>
<el-table-column prop="name" label="姓名" width="180"> </el-table-column>
<el-table-column prop="address" label="地址"> </el-table-column>
<el-table-column label="1月" prop="January" ></el-table-column>
<el-table-column label="2月" prop="February" ></el-table-column>
<el-table-column label="3月" prop="March" ></el-table-column>
</el-table>
</div>
</template><script>
export default {
data() {
return {
tableData: [
{date:"2024",address:"陕西省西安市吉祥村",January:'January',February:"February",March:'March'}
],
};
},
};
</script><style lang="scss" scoped>
/deep/.column-custom {
padding: 0px;
}
.header-div {
height: 80px;
position: relative;
}
.header-col1 {
position: absolute;
left: 0;
bottom: 0;
}
.header-col2 {
position: absolute;
right: 0;
top: 0;
}
.header-col3 {
position: absolute;
right: 0;
bottom: 0;
}
/deep/.el-table--border .el-table__cell:first-child .cell {
padding: 0;
}
.header-line1 {
padding-left: 0;
width: 1px;
height: 150px;
transform: rotate(-67deg); /*这里需要自己调整,根据线的位置*/
-webkit-transform-origin: top;
transform-origin: top;
background-color: red;/*这里需要自己调整,根据线条的颜色*/
}
.header-line2 {
padding-left: 0;
width: 1px;
height: 150px;
transform: rotate(-41deg); /*这里需要自己调整,根据线的位置*/
-webkit-transform-origin: top;
transform-origin: top;
background-color: blue;/*这里需要自己调整,根据线条的颜色*/
position: absolute;
top: 0;
left: 0;
}
</style>element ui el-table实现带斜线的双表头
实现思路
通过嵌套表头将两个标题设置在一个单元格内,再通过 CSS 样式增加斜线效果。
知识点:el-table、::before、transform
实现的代码
<el-table :data="tableData" border>
<!--重点代码:采用嵌套的方式-->
<el-table-column label="数据" align="right" width="150">
<el-table-column prop="name" label="数据指标" width="150">
</el-table-column>
</el-table-column>
<el-table-column
v-for="(col, i) in columnList"
:key="i"
:prop="col.prop"
:label="col.label"
align="center"
>
<template v-if="col.children">
<el-table-column
v-for="(item, index) in col.children"
:key="index"
:prop="item.prop"
:label="item.label"
>
</el-table-column>
</template>
</el-table-column>
</el-table><style scoped>
/*表头斜线*/
/*::v-deep 这里主要的作用就是用来强制修改element默认的样式*/
::v-deep .el-table thead.is-group th {
background: none;
padding: 0px;
}
::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type {
border-bottom: none;/*中间的横线去掉*/
}
::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type div.cell {
text-align: right;/*上边文字靠右*/
}
::v-deep .el-table thead.is-group tr:last-of-type th:first-of-type div.cell {
text-align: left;/*下边文字靠左*/
}
/*核心代码*/
::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type:before {
content: "";
position: absolute;
width: 1px;
height: 80px;/*斜线的长度*/
top: 0;
left: 0;
background-color: #18449C;
opacity: 1;
display: block;
transform: rotate(-61deg);/*调整斜线的角度*/
-webkit-transform-origin: top;
transform-origin: top;
}
::v-deep .el-table thead.is-group tr:last-of-type th:first-of-type:before {
content: "";
position: absolute;
width: 1px;
height: 80px;/*斜线的长度*/
bottom: 0;
right: 0;
background-color: #18449C;
opacity: 1;
display: block;
transform: rotate(-62deg);/*调整斜线的角度*/
-webkit-transform-origin: bottom;
transform-origin: bottom;
}
</style>总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
