vue elementUI table表格自定义样式滚动

复制代码
<template>
  <div class="table-wrapper">
    <el-table
      :header-cell-style="getRowClass"
      :row-class-name="tableRowClassName"
      :data="tableData"
      style="width: 100%;color:#fff; font-size: 12px;margin:0 auto;"
      ref="tableXj1"
      height="278px"
    >
      <el-table-column
        label="设备名称"
        prop="MACHINENAME"
        min-width="40"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="设备名称"
        prop="MACHINENAME"
        min-width="40"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="设备名称"
        prop="MACHINENAME"
        min-width="40"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="异常现象"
        prop="FAULTDESCRIBE"
        min-width="40"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="设备名称"
        prop="MACHINENAME"
        min-width="40"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="设备名称"
        prop="MACHINENAME"
        min-width="40"
        align="center"
      >
      </el-table-column>
    </el-table>
  </div>
</template>
<script>

export default {
  data() {
    return {
      intervalId: null,
      tableData: [
        { MACHINENAME: 10001, FAULTDESCRIBE: 'Test1' },
        { MACHINENAME: 10002, FAULTDESCRIBE: 'Test2' },
        { MACHINENAME: 10003, FAULTDESCRIBE: 'Test3' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
        { MACHINENAME: 10004, FAULTDESCRIBE: 'Test4' },
      ],
    }
  },

  mounted: function () {
    const tableXj1 = this.$refs.tableXj1
    const divDataXj1 = tableXj1.bodyWrapper
    this.intervalId = setInterval(() => {
      divDataXj1.scrollTop += 2
      if (divDataXj1.clientHeight + divDataXj1.scrollTop == divDataXj1.scrollHeight) {
        divDataXj1.scrollTop = 0
      }
    }, 100)
  },
  methods: {
    // 设置隔行变色
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 0) {
        return 'yellow'
      } else {
        return 'orange'
      }
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      return "background:rgba(31, 94, 167, 0.4);color:#326aff";
    },
  },
  beforeDestroy() {
    clearInterval(this.intervalId);
  },
}
</script>
<style scoped>
.table-wrapper /deep/ .el-table .el-table__body-wrapper {
    overflow-y: hidden !important;
}
.table-wrapper /deep/.el-table,
.el-table__expanded-cell {
    background-color: transparent !important;
}
.table-wrapper /deep/ tr,
.table-wrapper /deep/ th,
.table-wrapper /deep/ td {
    border-bottom: 0px;
}
.table-wrapper >>> .el-table__row > td {
    border: none;
}
.table-wrapper >>> .el-table th.el-table__cell.is-leaf {
    border-bottom: none !important;
}
.table-wrapper >>> .el-table__inner-wrapper::before {
    height: 0;
}
::v-deep .el-table__body {
    -webkit-border-vertical-spacing: 13px;
    border: none !important;
}
::v-deep .yellow {
    border: none !important;
    background: linear-gradient(90deg, rgba(31, 94, 167, 0) 3%, rgba(31, 94, 167, 0.4) 40%, rgba(31, 94, 167, 0.4) 70%, rgba(31, 94, 167, 0) 100%) !important;
}
::v-deep .orange {
    background: linear-gradient(90deg, rgba(31, 94, 167, 0) 3%, rgba(31, 94, 167, 0.2) 50%, rgba(31, 94, 167, 0.2) 70%, rgba(31, 94, 167, 0) 100%) !important;
}
.table-wrapper /deep/ .el-table th > .cell {
    color: #fff !important;
    border: none !important;
}
.table-wrapper /deep/ .el-table--fit {
    padding: 20px;
}

.table-wrapper /deep/ .el-table tr {
    background-color: transparent !important;
    border: none !important;
}
.table-wrapper /deep/ .el-table th > .cell {
    color: #fff !important;
}
.table-wrapper /deep/ .el-table--fit {
    padding: 20px;
}
.table-wrapper /deep/ .el-table,
.el-table__expanded-cell {
    background-color: transparent;
}

.table-wrapper /deep/ .el-table tr {
    background-color: transparent !important;
}
.table-wrapper /deep/ .el-table--enable-row-transition .el-table__body td,
.el-table .cell {
    background-color: transparent;
}
</style>
相关推荐
范文杰3 分钟前
AI 时代如何更高效开发前端组件?21st.dev 给了一种答案
前端·ai编程
拉不动的猪11 分钟前
刷刷题50(常见的js数据通信与渲染问题)
前端·javascript·面试
拉不动的猪19 分钟前
JS多线程Webworks中的几种实战场景演示
前端·javascript·面试
FreeCultureBoy1 小时前
macOS 命令行 原生挂载 webdav 方法
前端
uhakadotcom2 小时前
Astro 框架:快速构建内容驱动型网站的利器
前端·javascript·面试
uhakadotcom2 小时前
了解Nest.js和Next.js:如何选择合适的框架
前端·javascript·面试
uhakadotcom2 小时前
React与Next.js:基础知识及应用场景
前端·面试·github
uhakadotcom2 小时前
Remix 框架:性能与易用性的完美结合
前端·javascript·面试
uhakadotcom2 小时前
Node.js 包管理器:npm vs pnpm
前端·javascript·面试
LaoZhangAI3 小时前
2025最全GPT-4o图像生成API指南:官方接口配置+15个实用提示词【保姆级教程】
前端