element-plus 表格-自定义样式实现

效果如下

代码如下

javascript 复制代码
<template>
  <h2>表格自定义样式</h2>
  <div style="background-color: cadetblue; height: 600px;">
    <div class="regulaContainer">

      <el-table ref="tableRef" :data="tableData" border style="width: 100%" highlight-current-row height="400"
        :cell-style="rowStyleClass">
        <el-table-column type="index" label="序号" width="100" />
        <el-table-column prop="date" label="Date" width="180" />
        <el-table-column prop="name" label="Name" width="180" />
        <el-table-column prop="address" label="Address" />
      </el-table>

    </div>
  </div>
</template>

<script lang="ts" setup >
import { getCurrentInstance, onMounted, reactive, ref, inject } from 'vue'

const install = getCurrentInstance();
const tableRef = ref();
const tableData = reactive<any>([])

onMounted(() => {
  for (let i = 0; i < 5; i++) {
    let obj = {
      date: '2016-05-01',
      name: 'Tom' + i,
      address: 'No. 189, Grove St, Los Angeles',
      color_index: i
    }
    tableData.push(obj);
  }


})

function rowStyleClass(row) {
  console.log(row.rowIndex)
  let style = {};

  if (row.rowIndex % 2) {
    style = {
      color: '#fff',
      borderBottom: "1px solid #EBEEF588",
      //background: '#065D5F !important'
    };

    return style;
  }
  else {
    style = {
      color: '#fff',
      borderBottom: "1px solid #EBEEF588",
      //background: '#065D5F !important'
    };

    return style;
  }
}

</script> 


<style>
.regulaContainer {
  background-color: cadetblue;
}

/* 表格整体背景色 */
.regulaContainer .el-table,
.regulaContainer .el-table__expanded-cell {
  background-color: transparent;
}

/* 表格最下面的线 */
.regulaContainer .el-table__inner-wrapper::before {
  height: 0px;
}

.regulaContainer .el-table td.el-table__cell,
.regulaContainer .el-table th.el-table__cell.is-leaf {
  border: 0px;
}

.regulaContainer .el-table thead {
  color: #fff;
  background-color: rgb(4, 151, 145);
  border: 0;
}

.regulaContainer .el-table th {
  background: transparent;
}

/* 表格内tr背景色修改 */
.regulaContainer .el-table tr {
  background-color: transparent !important;
  border: 1px;
  /* 设置字体大小 */
  font-size: 16px;
  color: #fff;
}

/*表格内td背景色修改*/
.regulaContainer .el-table td {
  background-color: transparent !important;
  border: 1px;
  /* 设置字体大小 */
  font-size: 16px;
  color: #fff;
}

.regulaContainer .current-row {
  /* 选中时的图片显示 */
  background: rgb(26, 46, 161);
  background-size: 100% 100% !important;
}

/* 用来设置当前页面element全局table 鼠标移入某行时的背景色*/
.regulaContainer .el-table--enable-row-hover .el-table__body tr:hover>td {
  background-color: rgb(60, 10, 175) !important;
  /* color: #f19944; */
  /* 设置文字颜色,可以选择不设置 */
}
</style>
相关推荐
网络安全-老纪11 分钟前
网络安全-js安全知识点与XSS常用payloads
javascript·安全·web安全
yqcoder20 分钟前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
十八朵郁金香41 分钟前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
计算机-秋大田1 小时前
基于Spring Boot的兴顺物流管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·spring·课程设计
GDAL2 小时前
HTML 中的 Canvas 样式设置全解
javascript
GDAL2 小时前
HTML Canvas clip 深入全面讲解
前端·javascript·canvas
禾苗种树2 小时前
在 Vue 3 中使用 ECharts 制作多 Y 轴折线图时,若希望 **Y 轴颜色自动匹配折线颜色**且无需手动干预,可以通过以下步骤实现:
前端·vue.js·echarts
GISer_Jing2 小时前
Javascript排序算法(冒泡排序、快速排序、选择排序、堆排序、插入排序、希尔排序)详解
javascript·算法·排序算法
JustHappy2 小时前
「我们一起做组件库🌻」做个面包屑🥖,Vue的依赖注入实战💉(VersakitUI开发实录)
前端·javascript·github
拉不动的猪3 小时前
刷刷题16
前端·javascript·面试