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>
相关推荐
Hi_kenyon4 小时前
VUE3套用组件库快速开发(以Element Plus为例)二
开发语言·前端·javascript·vue.js
Irene19914 小时前
Vue 3 响应式系统类型关系总结(附:computed、props)
vue.js·props·响应式类型
起名时在学Aiifox4 小时前
Vue 3 响应式缓存策略:从页面状态追踪到智能数据管理
前端·vue.js·缓存
天若有情6734 小时前
校园二手交易系统实战开发全记录(vue+SpringBoot+MySQL)
vue.js·spring boot·mysql
xiaobai1784 小时前
测试工程师入门AI技术 - 前序:跨越焦虑,从优势出发开启学习之旅
人工智能·学习
北岛寒沫4 小时前
北京大学国家发展研究院 经济学原理课程笔记(第二十一课 金融学基础)
经验分享·笔记·学习
扑火的小飞蛾4 小时前
网络安全小白学习路线图 (基于提供文档库)
学习·安全·web安全
优雅的潮叭4 小时前
c++ 学习笔记之 malloc
c++·笔记·学习
计算机程序设计小李同学4 小时前
个人数据管理系统
java·vue.js·spring boot·后端·web安全
EndingCoder5 小时前
Any、Unknown 和 Void:特殊类型的用法
前端·javascript·typescript