
element-ui el-table 树形结构子节点不能打勾
问题描述:
在 element-ui 的 el-table 树形结构中,点击子节点时,可以选中但不会出现打勾效果。
解决方案:
解决这个问题需要遵循以下步骤:
- 确保使用 element-ui 的最新版本: element-ui 版本问题可能导致此问题。建议升级到最新版本。
- 自定义 css 样式: 添加以下 css 样式以自定义选中行的样式:
::v-deep .indeterminate .el-table-column--selection .cell .el-checkbox {
display: block !important;
}
::v-deep .indeterminate .el-checkbox__input .el-checkbox__inner {
background-color: #4a97eb !important;
border-color: #4a97eb !important;
color: #fff !important;
}
::v-deep .indeterminate .el-checkbox__input.is-checked .el-checkbox__inner::after {
transform: scale(0.5);
}
::v-deep .indeterminate .el-checkbox__input .el-checkbox__inner::after {
border-color: #c0c4cc !important;
background-color: #c0c4cc;
}
::v-deep .indeterminate .el-checkbox__input .el-checkbox__inner::after {
content: "";
position: absolute;
display: block;
background-color: #fff;
height: 2px;
transform: scale(0.5);
left: 0;
right: 0;
top: 5px;
width: auto !important;
}- 更新选中行的样式: 设置 .row-class-name prop 以自定义选中行的样式类名,并使用以下 css 样式:
::v-deep .indeterminate {
background-color: #f5f5f5;
}问题补充:选中的节点中出现一半勾选的状态
如果选中行后出现一半勾选的状态,可以按以下步骤解决:
- 设置 :row-key prop:确保为每个行设置唯一键,以便 el-table 正确跟踪选中的行。
- 自定义 handleselectionchange 事件:在 handleselectionchange 事件中,判断所选行的数量并更新选中行的 isselect 状态。
- 自动选中子节点:如果选中父节点,则自动选中所有子节点。
通过以上步骤,可以解决 el-table 树形结构子节点不能打勾以及选中节点出现一半勾选状态的问题。










