vxetable 如何修改行点击高亮背景色

8 篇文章 0 订阅
7 篇文章 0 订阅

在使用vxetable中的表格组件时,有时会遇到修改点击高亮行背景色的情况。要修改高亮行背景色只需要以下两步即可

  1. 根据current-change 事件获取并记录当前点击高亮行的点击索引
  2. 根据row-style 属性绑定的方法,根据回调参数{rowIndex} ,判断如果当前索引和记录点击高亮行的索引相同,则

    根据传入的高亮背景色,对行样式进行设置即可

    // 简单示例
    <template>
    <vxe-table  :row-style="rowStyle"  @current-change="onCurrentChange"></vxe-table>
    </template>
    <script>
       import { reactive, toRefs, defineComponent, PropType, computed, ref, watch, nextTick } from 'vue';
        
        const state = reactive({
            highlightIndex:0,
            highlightRowBgColor:'red'
        })
        
        /**
         * @description: 当切换选中行时
         * @return {*}
         */
        const onCurrentChange = ({ rowIndex }: any) => {
          state.highlightIndex = rowIndex;
        }; 
        
        /**
         * @description: 动态设置表格内容样式
         * @return {*}
         */
        const rowStyle = ({ rowIndex }: any) => {
          const rowStyleMap = {
          } as any;
    
    
          // 如果当前开启高亮行选择,高亮行权重比奇偶行设置的权重高
          if (state.highlightIndex === rowIndex) {
            rowStyleMap.backgroundColor = state.highlightRowBgColor;
          }
    
          return rowStyleMap;
        };
    </script>

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值