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>

效果如下:

相关推荐
蒜香拿铁2 小时前
Angular【起步】
前端·javascript·angular.js
Hilaku2 小时前
前端开发,真的有必要学Docker吗?
前端·javascript·docker
一枚前端小能手3 小时前
🗂️ 文件系统API深度解析 - 让Web应用拥有本地文件操作能力的现代API实战指南
前端·javascript
一枚前端小能手3 小时前
「周更第10期」实用JS库推荐:VueUse
前端·javascript·vue.js
前端摸鱼匠3 小时前
Vue 3 事件修饰符全解析:从 .stop 到 .passive,彻底掌握前端交互的艺术
前端·vue.js·node.js·vue·交互
小摇3 小时前
空值合并运算符`??`和逻辑或运算符 `||` 的区别
javascript
FinClip3 小时前
工行APP深夜惊魂!账户一夜清零,金融机构如何筑牢数字防火墙?
前端·javascript·github
inx1773 小时前
从拼接到优雅:用 ES6 模板字符串和 map 打造更简洁的前端代码
前端·javascript·dom
前端伪大叔4 小时前
第26篇:爆赚利器!三步搞定 Freqtrade 核心买卖信号,手把手教你写自动交易策略!
javascript·mysql·微信
烟袅4 小时前
从一行代码说起:深入理解 JavaScript 中的字符串类型与模板字符串
前端·javascript·代码规范