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