element-ui tree修改点击父节点的背景色
时间: 2023-10-14 13:16:38 浏览: 44
要修改 Element UI 的 Tree 组件中点击父节点的背景色,可以通过以下方式进行:
1. 在 CSS 中为选中的节点添加样式。
```
.el-tree-node.is-selected:not(.is-current):not(.is-expanded):not([aria-level="1"]) {
background-color: #f5f7fa;
}
```
2. 在 CSS 中为展开的节点添加样式。
```
.el-tree-node.is-expanded:not(.is-current):not([aria-level="1"]) {
background-color: #f5f7fa;
}
```
3. 在 CSS 中为当前节点添加样式。
```
.el-tree-node.is-current:not([aria-level="1"]) {
background-color: #f5f7fa;
}
```
将以上样式添加到你的 CSS 文件中,然后在 Tree 组件中添加 class 名称即可。
```
<template>
<el-tree class="tree"></el-tree>
</template>
<style>
.tree .el-tree-node.is-selected:not(.is-current):not(.is-expanded):not([aria-level="1"]) {
background-color: #f5f7fa;
}
.tree .el-tree-node.is-expanded:not(.is-current):not([aria-level="1"]) {
background-color: #f5f7fa;
}
.tree .el-tree-node.is-current:not([aria-level="1"]) {
background-color: #f5f7fa;
}
</style>
```