vue e-table设置选中样式
时间: 2023-07-01 15:24:41 浏览: 117
如果你使用的是Vue.js和element-ui中的e-table组件,可以使用以下代码设置选中行的样式:
```html
<template>
<div>
<el-table :data="users" @row-click="selectRow" highlight-current-row>
<el-table-column label="ID" prop="id"></el-table-column>
<el-table-column label="Name" prop="name"></el-table-column>
<el-table-column label="Email" prop="email"></el-table-column>
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
users: [
{ id: 1, name: 'Alice', email: 'alice@example.com' },
{ id: 2, name: 'Bob', email: 'bob@example.com' },
{ id: 3, name: 'Charlie', email: 'charlie@example.com' },
],
selectedRow: null,
};
},
methods: {
selectRow(row) {
this.selectedRow = row;
},
},
};
</script>
<style scoped>
.el-table--highlight-current-row .el-table__row--current {
background-color: #cce5ff;
}
</style>
```
在上面的代码中,我们使用`@row-click`事件监听行的点击事件,在`selectRow`方法中,我们更新`selectedRow`的值,以便动态绑定选中行的样式。同时,我们通过`highlight-current-row`属性开启了高亮当前行的功能。在样式中,我们使用了`.el-table--highlight-current-row .el-table__row--current`选择器来设置选中行的样式。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)