Vue 学习随笔系列十七 -- 表格样式修改

表格样式修改

文章目录


一、表格背景颜色修改

1、方法一

表格外套一个 div ,修改div的背景色,并将表格背景色设置为透明

参考代码:

bash 复制代码
<template>
    <div class="custom-table">
        <el-table
            size="mini"
            border
            :data="tableData"
            :max-height="tableHeight"
            style="width: 100%">
            <el-table-column
                v-for="(item, index) in tableColumns"
                :key="index"
                v-bind="item"
                align="center"
                >
            </el-table-column>
            <el-table-column
                label="操作"
                fixed="right"
                align="center"
                width="100"
            >
                <template slot-scope="scope">
                    <span
                        class="del-btn"
                        @click="emitEvent({eventName:'deleteItem',params:scope.row})"
                    >删除</span>
                </template>
            </el-table-column>           
        </el-table>
    </div>
</template>

<script>
    export default {
        props: { 
            tableData: {
                type: Array,
                default: () => []
            },
            tableHeight: {},
            tableColumns: {
                default: () => []
            }
        },
        data() {
            return { }
        }, 
    }
</script>

<style lang="less" scoped>
    .del-btn {
        color: #4597EB;
        cursor: pointer;
    }

    .custom-table /deep/ .el-table, .el-table__expaned-cell {
        background-color: transparent;
    }
    .custom-table /deep/ .el-table tr {
        background-color: transparent !important;
    }
    .custom-table /deep/  .el-table--enable-row-transition .el-table__body td, .el-table .cell{
        background-color: transparent;
    }
    .custom-table /deep/ .el-table th.el-table__cell {
        background: transparent !important; // 表头背景透明
    }
    .el-table::before { //去除底部白线
        left: 0;
        bottom: 0;
        width: 100%;
        height: 0px;
    }
</style>

2、方法二

直接修改表格背景颜色

bash 复制代码
<template>
    <div class="custom-table">
        <el-table
            size="mini"
            border
            :data="tableData"
            :max-height="tableHeight"
            style="width: 100%">
            <el-table-column
                v-for="(item, index) in tableColumns"
                :key="index"
                v-bind="item"
                align="center"
                >
            </el-table-column>
            <el-table-column
                label="操作"
                fixed="right"
                align="center"
                width="100"
            >
                <template slot-scope="scope">
                    <span
                        class="del-btn"
                        @click="emitEvent({eventName:'deleteItem',params:scope.row})"
                    >删除</span>
                </template>
            </el-table-column>           
        </el-table>
    </div>
</template>

<script>
    export default {
        props: { 
            tableData: {
                type: Array,
                default: () => []
            },
            tableHeight: {},
            tableColumns: {
                default: () => []
            }
        },
        data() {
            return {
                
            }
        },
        methods: {
            emitEvent ({ eventName, params }) {
                this.$emit(eventName, params)
            }
        }, 
    }
</script>

<style lang="less" scoped>
    .del-btn {
        color: #4597EB;
        cursor: pointer;
    }
    .custom-table {
        background: transparent;
    }
    .custom-table /deep/ .el-table th.el-table__cell,
    /deep/ .el-table tr,
    /deep/.el-table th {
    	color: '#FFF'; // 表格字体颜色
        background: red; // 表格背景颜色
    }

</style>

二、多级表头颜色修改

bash 复制代码
<template>
   <el-table 
	   :data="tableData" 
	   :header-cell-style="tableHeaderColor" 
	   border 
	   stripe
   >
</template>

<script>
export default {
    methods: {
         // 修改表头颜色
        tableHeaderColor ({ rowIndex, columnIndex }) {
            if (rowIndex === 0 && columnIndex === 0) {
                return "background:#D9EAFFFF;";
            }
            if (rowIndex === 0 && columnIndex === 2) {
                return "background: #FFF0E1FF;";
            }
            if (rowIndex === 0 && columnIndex === 3) {
                return "background: #E0F5E9FF;";
            }
            if (rowIndex === 0 && columnIndex === 4) {
                return "background: #D9EAFFFF;";
            }
            if (rowIndex === 0 && columnIndex === 5) {
                return "background: #FFF0E1FF;";
            }
            if (rowIndex === 0 && columnIndex === 6) {
                return "background: #E0F5E9FF;";
            }
        },
    }
}
</script>

<style>

</style>
相关推荐
黄鹂绿柳20 分钟前
Vue+Vite学习笔记
vue.js·笔记·学习
来自星星的坤25 分钟前
【Vue 3 + Vue Router 4】如何正确重置路由实例(resetRouter)——避免“VueRouter is not defined”错误
前端·javascript·vue.js
985小水博一枚呀4 小时前
【AI大模型学习路线】第二阶段之RAG基础与架构——第七章(【项目实战】基于RAG的PDF文档助手)技术方案与架构设计?
人工智能·学习·语言模型·架构·大模型
香蕉可乐荷包蛋4 小时前
浅入ES5、ES6(ES2015)、ES2023(ES14)版本对比,及使用建议---ES6就够用(个人觉得)
前端·javascript·es6
未来之窗软件服务5 小时前
资源管理器必要性———仙盟创梦IDE
前端·javascript·ide·仙盟创梦ide
hello1114-6 小时前
Redis学习打卡-Day3-分布式ID生成策略、分布式锁
redis·分布式·学习
小Tomkk6 小时前
2025年PMP 学习二十 第13章 项目相关方管理
学习·pmp·项目pmp
西哥写代码6 小时前
基于cornerstone3D的dicom影像浏览器 第十八章 自定义序列自动播放条
前端·javascript·vue
独行soc6 小时前
2025年渗透测试面试题总结-百度面经(题目+回答)
运维·开发语言·经验分享·学习·面试·渗透测试·php
清风细雨_林木木6 小时前
Vue 中生成源码映射文件,配置 map
前端·javascript·vue.js