element ui 点击表格某一行改变行背景颜色

template

<el-table

	:data="data"
	
	:row-class-name="tableRowClassName" //设置类
	
	:row-style="selectedstyle" //设置行的样式
	
	@row-click="rowClick" //点击

>

</el-table>

script

data() {
    return {
         data:[],
   		 getIndex:"",
    }
},
methods: {
	selectedstyle ({row, rowIndex}) {
		if ((this.getIndex) === rowIndex ) {
			return {
			"background-color": "red"
			};
		}
	},
	tableRowClassName ({row, rowIndex}) {
		row.index = rowIndex;
	},
	rowClick (row) {
		this.getIndex=row.index
	}
}

猜你喜欢

转载自blog.csdn.net/a791226606/article/details/106262204