<el-tree
class="filter-tree"
:data="data"
node-key="id"
:props="defaultProps"
:check-strictly='true'
default-expand-all
show-checkbox
@check-change="handleCheckChange"
ref="tree">
</el-tree>
核心代码:
handleCheckChange(data, checked, indeterminate) {
this.$nextTick(() => {
if(checked) {
let nodes = this.$refs.tree.getCheckedNodes();
if(nodes.length == 0) {
this.pid = ''
} else if(nodes.length == 1) {
this.pid = nodes[0].pid
this.$refs.tree.setChecked(nodes[0], true);
} else {
if(data.pid !== this.pid) {
this.$refs.tree.setChecked(data, false);
} else {
this.$refs.tree.setChecked(data, true);
}
}
}
})
},