element中el-table表头通过header-row-style设置样式

文章目录

一、知识点

有些时候需要给element-ui表头设置不同样式,比如居中、背景色、字体大小等等,这时就可以用到本文要说的属性header-row-style。官网说明如下所示:

二、设置全部表头

2.1、方式一

html 复制代码
<el-table :header-cell-style="{'text-align': 'center'}" />

2.2、方式二

vue 复制代码
<template>
	<el-table :header-cell-style="tableHeaderColor" />
</template>
<script>
export default {
	methods: {
		tableHeaderColor ({row, column, rowIndex, columnIndex}) {
			return 'text-align: center;'
		}
	}
}
</script>

三、设置某个表头

vue 复制代码
<template>
	<el-table :header-cell-style="tableHeaderColor" />
</template>
<script>
export default {
	methods: {
		// 设置表头的颜色
		tableHeaderColor({ row, column, rowIndex, columnIndex }) {
			console.log(row, column, rowIndex, columnIndex);
			if (rowIndex === 0 && columnIndex === 1) {
				return 'background-color: #afccfd; color:#000000;'; //蓝色
			} else if (rowIndex === 0 && columnIndex === 2) {
				return 'background-color: #c0e33c; color:#000000;';//绿色
			} else if (rowIndex === 0 && columnIndex === 3) {
				return 'background-color: #fbc57b; color:#000000;';//橙色
			} else {
				return 'color:#000000; background: #ffffff;';
			}
		}
	}
}
</script>

效果如下所示:

四、最后

本人每篇文章都是一字一句码出来,希望大佬们多提提意见。顺手来个三连击,点赞👍收藏💖关注✨。创作不易,给我打打气,加加油☕

相关推荐
苏一恒5 分钟前
MP4 在 <video> 里,必须全量下载才能起播吗?—— moov、Range 与被误解的 FastStart
前端
Java小卷13 分钟前
低代码并没有过时!可拖拽表单设计器布局思路
前端·低代码
idcu15 分钟前
深入 Lyt.js 响应式系统:Proxy + Signal 双模式
前端
idcu16 分钟前
Vapor Mode 揭秘:无虚拟 DOM 的极致性能
前端
idcu18 分钟前
从 Vue 3 到 Lyt.js:无痛迁移指南
前端
尘世壹俗人19 分钟前
如何检查服务器上消耗资源的程序是那个
服务器·前端·chrome
LIO24 分钟前
Vue Router 进阶:深入用法与最佳实践
前端·vue-router
Hilaku34 分钟前
做了 6 年前端,技术不差却拿不到 Offer?
前端·javascript·程序员
古茗前端团队34 分钟前
钉钉小程序蓝牙打印探索与实践
前端·蓝牙
LIO40 分钟前
一文看懂 Vue Router:精简、易懂、直接用
前端·vue-router