ElementPlus表格中的背景透明

ElementPlus表格中的背景透明

最近写大屏,用到elementplus中的el-table,为了让显示效果好看一点,需要把表格的白色背景调整为透明,与整个背景融为一体。可以参考的资料非常少,大部分都是ElmentUI的方法,在某个前端开发群里问了一下解决方案,大佬给出的解决方案直接让我拍案叫绝,记录一下,以后翻起来更容易

直接上代码:

vue 复制代码
<template>
    <el-table :data="tableData" height="300" :row-style="rowstyle">
        <el-table-column v-for="(item, index) in tableForm" :key="index" :prop="item.prop" :label="item.label"
            show-overflow-tooltip></el-table-column>
    </el-table>
</template>

<script setup>
import { ref, onMounted, toRefs } from 'vue'
// import { getHighwayTrafficApi } from '@/apis/predictTraffic'

const tableForm = [
    { prop: 'road_name', label: '路名', width: 20 },
    { prop: 'section_desc', label: '堵点', width: 40 },
    { prop: 'speed', label: '速度', width: 20 },
    { prop: 'status', label: '状态', width: 20 },
    { prop: 'congestion_distance', label: '长度', width: 20 },
    { prop: 'congestion_trend', label: '趋势', width: 20 },

]

const props = defineProps({
    tableData: Array
})

const rowstyle = ({ row, rowIndex }) => {
    if (rowIndex % 2 === 0) {
        return {
            backgroundColor: 'rgba(3, 76, 106, 1)',
        }
    }
}

</script>

<style lang="scss" scoped>
.el-table {
    --el-table-border-color: transparent;
    --el-table-border: none;
    --el-table-text-color: #bdbdbe;
    --el-table-header-text-color: #bdbdbe;
    --el-table-row-hover-bg-color: transparent;
    --el-table-current-row-bg-color: transparent;
    --el-table-header-bg-color: transparent;
    --el-table-bg-color: transparent;
    --el-table-tr-bg-color: transparent;
    --el-table-expanded-cell-bg-color: transparent;
}
</style>

效果如下:

相关推荐
IT码农-爱吃辣条1 小时前
Three.js 初级教程大全
开发语言·javascript·three.js
四岁半儿1 小时前
vue,H5车牌弹框定制键盘包括新能源车牌
前端·vue.js
烛阴2 小时前
告别繁琐的类型注解:TypeScript 类型推断完全指南
前端·javascript·typescript
gnip2 小时前
工程项目中.env 文件原理
前端·javascript
JohnYan3 小时前
工作笔记 - CentOS7环境运行Bun应用
javascript·后端·容器
东风西巷5 小时前
Rubick:基于Electron的开源桌面效率工具箱
前端·javascript·electron·软件需求
Miracle_G5 小时前
每日一个知识点:JavaScript 箭头函数与普通函数比较
javascript
unfetteredman5 小时前
Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found
前端·javascript·vite
HANK6 小时前
KLineChart 绘制教程
前端·vue.js
程序员小续6 小时前
React 官方严令禁止:Hook 不能写在 if/else,真相竟然是…
前端·javascript·程序员