直接利用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);
}
}
};
},