Vue ElementUI table给表格一个斜线分隔线

方式一:参考element表格表头斜杠,让你的数据更有条理_el-table 表头斜线-CSDN博客

缺点:当屏幕放大或者缩小的时候,斜线会变形,得使用@media screen根据屏幕大小一个个去调整,调得太麻烦了,就放弃了这种方式,感兴趣的可以试试

<el-table :data="tableData" border style="width: 100%">
	<el-table-column label="类型" width="150" align="center">
	     <el-table-column label="月份" width="150"></el-table-column>
    </el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
	<el-table-column label="日期"></el-table-column>
</el-table>
样式如下
/deep/ .el-table thead.is-group tr:first-of-type th:first-of-type {
		border-bottom: none; // 去掉中间横线
	}

	/deep/ .el-table thead.is-group tr:first-of-type th:first-of-type div.cell {
		text-align: right; // 上边文字靠右
	}
	/deep/ .el-table thead.is-group tr:last-of-type th:first-of-type div.cell {
		text-align: left; // 下边文字靠左
	}

	/deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
		content: '';
		position: absolute;
		width: 1px;
		height: 100px; // 斜线长度
		top: 0;
		left: 0;
		background-color: #fff;
		opacity: 0.2;
		display: block;
		transform: rotate(-43deg);
		transform: rotate(-71deg);
		// transform: rotate(286deg);
		-webkit-transform-origin: top;
		transform-origin: top;
	}

	/deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
		content: '';
		position: absolute;
		width: 1px;
		height: 100px;
		bottom: 0;
		right: 0;
		background-color: #fff;
		opacity: 0.2;
		display: block;
		transform: rotate(-43deg);
		transform: rotate(-70deg);
		// transform: rotate(286deg);
		-webkit-transform-origin: bottom;
		transform-origin: bottom;
	}
	@media screen and(min-width: 550px) and (max-width: 1430px) {
		/deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
			transform: rotate(-62deg);
		}
		/deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
			transform: rotate(-62deg);
		}
	}
	@media screen and(min-width: 1430px) and (max-width: 1450px) {
		/deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
			transform: rotate(-62deg);
		}
		/deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
			transform: rotate(-62deg);
		}
	}

方式二:参考滑动验证页面

页面放大缩小斜线位置都不受影响

<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-line"></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月"></el-table-column>
			<el-table-column label="2月"></el-table-column>
			<el-table-column label="3月"></el-table-column>
			<el-table-column label="4月"></el-table-column>
			<el-table-column label="5月"></el-table-column>
			<el-table-column label="6月"></el-table-column>
			<el-table-column label="7月"></el-table-column>
			<el-table-column label="8月"></el-table-column>
			<el-table-column label="9月"></el-table-column>
			<el-table-column label="10月"></el-table-column>
			<el-table-column label="11月"></el-table-column>
			<el-table-column label="12月"></el-table-column>
		</el-table>

样式:
/deep/.column-custom {
	padding: 0px !important;
}

/deep/.el-table--border .el-table__cell:first-child .cell {
	padding: 0 !important;
}
.header-div {
	height: 50px;
	position: relative;
}
.header-col1 {
	position: absolute;
	left: 0;
	bottom: 0;
}
.header-col2 {
	position: absolute;
	right: 0;
	top: 0;
}
.header-line {
	padding-left: 0;
	width: 1px;
	height: 150px;
	transform: rotate(-67deg); /*这里需要自己调整,根据线的位置*/
	-webkit-transform-origin: top;
	transform-origin: top;
	background-color: #fff;
}

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue ElementUI提供了非常方便的表格组件,并且内置了排序功能。只需要在表格的`<el-table-column>`元素上指定`prop`属性和`sortable`属性即可实现排序。 以下是一个基本的示例代码: ``` <template> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="date" label="日期" sortable></el-table-column> <el-table-column prop="name" label="姓名" sortable></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { date: '2021-01-01', name: '张三', address: '北京市' }, { date: '2021-01-02', name: '李四', address: '上海市' }, { date: '2021-01-03', name: '王五', address: '广州市' }, ], }; }, }; </script> ``` 在上面的代码中,我们在`<el-table-column>`元素上指定了`prop`和`sortable`属性,其中`prop`属性对应表格数据中的字段名,`sortable`属性指定该列可以排序。 如果我们希望默认按某个字段升序排序怎么办呢?我们可以在`<el-table>`元素上指定`default-sort`属性,如下所示: ``` <template> <el-table :data="tableData" style="width: 100%" :default-sort="{ prop: 'date', order: 'ascending' }"> <el-table-column prop="date" label="日期" sortable></el-table-column> <el-table-column prop="name" label="姓名" sortable></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { date: '2021-01-01', name: '张三', address: '北京市' }, { date: '2021-01-02', name: '李四', address: '上海市' }, { date: '2021-01-03', name: '王五', address: '广州市' }, ], }; }, }; </script> ``` 在上面的代码中,我们在`<el-table>`元素上指定了`default-sort`属性,它是一个对象,包含两个属性:`prop`表示默认排序的字段名,`order`表示默认排序的方式,取值为`ascending`(升序)或`descending`(降序)。这样,表格就会默认按日期升序排序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值