ant desing vue table 点击表格,实现背景行变色


1、直接利用rowClassName这个参数,直接上代码

<a-table 
:rowClassName="(record,index)=>{ retrun index===selectIndex?'active':' '}"
:customRow="rowClick"
></table>
 
data(){
  return{
   selectIndex=null
  }
},
method:{
rowClick(record,index){
return{
  props:{}
  on:{
    click: event => {
     this.selectIndex=index
      }
    }
 
 }
  
}
}

另外在全局样式中加上 .active的样式。ps: 这个全局样式要在main.js中定义在antd.less的下面,否则没办法覆盖antd.less中的样式

 

2、单击行使该行选中

<a-table
      :customRow="handleCheck"
      :rowSelection="{type:'radio',onChange:onSelectChange,selectedRowKeys}"    
    >
</a-table>
 
    handleCheck(record, index) {
      return {
        on: {
          click: () => {
            let code = this.modeType;
            if (this.selectedRowKeys) {
              this.selectedRowKeys = [];
            }
            if (this.selectedRows) {
              this.selectedRows = [];
            }
            this.selectedRowKeys.push(record[code]);
            this.selectedRows.push(record);
          }
        }
      };
    },

 

 

原文链接:https://blog.csdn.net/czx3387170/article/details/111170947

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM