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