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>

效果如下所示:

四、最后

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

相关推荐
前端大白话14 分钟前
救命!这10个Vue3技巧藏太深了!性能翻倍+摸鱼神器全揭秘
前端·javascript·vue.js
嘻嘻嘻嘻嘻嘻ys16 分钟前
《Vue 3全栈架构实战:Vite工程化、Pinia状态管理与Nuxt 3深度解析》
前端·后端
前端大白话17 分钟前
前端人必看!10个JavaScript“救命”技巧,让你告别加班改Bug
前端·javascript·程序员
Rudon滨海渔村23 分钟前
【Tauri】桌面程序exe开发 - Tauri+Vue开发Windows应用 - 比Electron更轻量!8MB!
javascript·electron·tauri·桌面应用
cg501727 分钟前
Vue回调函数中的this
前端·javascript·vue.js
前端太佬29 分钟前
从零到一实现扫码登录:一个前端菜鸟的踩坑实录
前端·javascript·架构
yuanmenglxb200440 分钟前
微信小程序核心技术栈
前端·javascript·vue.js·笔记·微信小程序·小程序
爱编程的鱼40 分钟前
如何让 HTML 文件嵌入另一个 HTML 文件:详解与实践
前端·html
_09271 小时前
Vue 2 与 Vue 3 的核心区别及 Vue 3 新特性详解
前端
David凉宸1 小时前
一文带你使用Vue完成移动端(apk)项目
前端