• vxe-table 将表格指定行设置颜色后,选中行、悬浮行样式失效解决。


    一、 表格悬浮行、选中行高

    1.效果

    在这里插入图片描述

    2.代码

    说明:给表格添加 :row-config="{isHover: true,isCurrent:true}" 即可

    <template>
      <div>
        <vxe-table
          ref="xTable"
          height="400"
          :row-config="{isHover: true,isCurrent:true}"
          :data="tableData"
        >
          <vxe-column type="seq" width="60"></vxe-column>
          <vxe-column field="name" title="Name"></vxe-column>
          <vxe-column field="age" title="Age" sortable></vxe-column>
          <vxe-column field="address" title="Address" show-overflow></vxe-column>
        </vxe-table>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          tableData: [
            { id: 10001, name: 'Test1', role: 'Develop',  age: 28, address: 'test abc' },
            { id: 10002, name: 'Test2', role: 'Test', age: 22, address: 'Guangzhou' },
            { id: 10003, name: 'Test3', role: 'PM',  age: 32, address: 'Shanghai' },
            { id: 10004, name: 'Test4', role: 'Designer',  age: 23, address: 'test abc' },
            { id: 10005, name: 'Test5', role: 'Develop',  age: 30, address: 'Shanghai' },
            { id: 10006, name: 'Test6', role: 'Designer',  age: 21, address: 'test abc' },
            { id: 10007, name: 'Test7', role: 'Test', age: 29, address: 'test abc' },
            { id: 10008, name: 'Test8', role: 'Develop',  age: 35, address: 'test abc' }
          ],
          
        }
      }
    }
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    二、 初始化表格 指定行设置背景颜色

    1. 效果

    在这里插入图片描述

    2.代码
    1. 给表格添加配置 :row-class-name="rowClassName"
    2. 在 methods 里编写过滤行方法 rowClassName,返回值是样式类名
    3. 在样式中设置背景颜色,样式名 ::v-deep .my-table .vxe-body--row.row-yellow。其中 .my-table 是表格类名,防止样式覆盖影响其他表格。
    <template>
      <div class="box">
        <vxe-table
          class="my-table"
          ref="xTable"
          height="400"
          :row-config="{isHover: true,isCurrent:true}"
          :data="tableData"
          :row-class-name="rowClassName"
        >
          <vxe-column type="seq" width="60"></vxe-column>
          <vxe-column field="name" title="Name"></vxe-column>
          <vxe-column field="age" title="Age" sortable></vxe-column>
          <vxe-column field="address" title="Address" show-overflow></vxe-column>
        </vxe-table>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          tableData: [
            { id: 10001, name: 'Test1', role: 'Develop', age: 28, address: 'test abc' },
            { id: 10002, name: 'Test2', role: 'Test', age: 22, address: 'Guangzhou' },
            { id: 10003, name: 'Test3', role: 'PM', age: 32, address: 'Shanghai' },
            { id: 10004, name: 'Test4', role: 'Designer', age: 23, address: 'test abc' },
            { id: 10005, name: 'Test5', role: 'Develop', age: 30, address: 'Shanghai' },
            { id: 10006, name: 'Test6', role: 'Designer', age: 21, address: 'test abc' },
            { id: 10007, name: 'Test7', role: 'Test', age: 29, address: 'test abc' },
            { id: 10008, name: 'Test8', role: 'Develop', age: 35, address: 'test abc' }
          ],
        }
      },
      methods: {
        rowClassName({ row }) {
          if (row.age >= 30) {
            return 'row-yellow'
          }
        }
      }
    }
    
    </script>
    
    <style scoped>
    .box {
      width: 700px;
      margin: 100px;
    }
    
    ::v-deep .my-table .vxe-body--row.row-yellow {
      background-color: #e1ed8952;
      z-index: 99;
    }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    3. 问题

    在这里插入图片描述
    在这里插入图片描述

    • 官方给出的说明如下:
      在这里插入图片描述

    三、 解决选中行、悬浮行样式失效

    1. 效果
    • 条件成立时,显示初始化样式。悬浮行显示灰色,选中行显示蓝色。

    在这里插入图片描述

    2.代码

    通过设置 z-index 来调节,具体实现见 style 部分。

    <template>
      <div class="box">
        <vxe-table
          class="my-table"
          ref="xTable"
          height="400"
          :row-config="{isHover: true,isCurrent:true}"
          :data="tableData"
          :row-class-name="rowClassName"
        >
          <vxe-column type="seq" width="60"></vxe-column>
          <vxe-column field="name" title="Name"></vxe-column>
          <vxe-column field="age" title="Age" sortable></vxe-column>
          <vxe-column field="address" title="Address" show-overflow></vxe-column>
        </vxe-table>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          tableData: [
            { id: 10001, name: 'Test1', role: 'Develop', age: 28, address: 'test abc' },
            { id: 10002, name: 'Test2', role: 'Test', age: 22, address: 'Guangzhou' },
            { id: 10003, name: 'Test3', role: 'PM', age: 32, address: 'Shanghai' },
            { id: 10004, name: 'Test4', role: 'Designer', age: 23, address: 'test abc' },
            { id: 10005, name: 'Test5', role: 'Develop', age: 30, address: 'Shanghai' },
            { id: 10006, name: 'Test6', role: 'Designer', age: 21, address: 'test abc' },
            { id: 10007, name: 'Test7', role: 'Test', age: 29, address: 'test abc' },
            { id: 10008, name: 'Test8', role: 'Develop', age: 35, address: 'test abc' }
          ],
        }
      },
      methods: {
        rowClassName({ row }) {
          if (row.age >= 30) {
            return 'row-yellow'
          }
        }
      }
    }
    
    </script>
    
    <style scoped>
    .box {
      width: 700px;
      margin: 100px;
    }
    
    ::v-deep .my-table .vxe-body--row.row-yellow {
      background-color: #e1ed8952;
       z-index: 99;
    }
    
    ::v-deep .my-table .vxe-body--row.row--hover {
      background-color: #f5f7fa;
      z-index: 959;
    }
    
    ::v-deep .my-table .vxe-body--row.row--current {
      background-color: #e6f7ff;
      z-index: 999;
    }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
  • 相关阅读:
    【OpenCV 例程200篇】235. 特征提取之主成分分析(sklearn)
    Java File.listFiles方法具有什么功能呢?
    【Proteus仿真】8位数码管动态扫描显示变化数据
    游戏登录界面制作
    浅谈设计模式(五)
    全球著名漫画家蔡志忠创作的“EIS元宇宙之门”数字艺术品限量发售!11.29正式开售
    【数据结构】二叉树的·深度优先遍历(前中后序遍历)and·广度优先(层序遍历)
    nodejs毕业设计源码基于node.js的博客系统
    ElementUI 组件设置全局默认值
    redis之集群
  • 原文地址:https://blog.csdn.net/qq_45325810/article/details/126606382