需要获取被选中的所有节点:
<el-tree
ref="tree"
class="tenant_tree"
:data="list"
show-checkbox
:props="defaultProps"
default-expand-all
node-key="tenantId"
highlight-current
@check-change="handleCheckChange"
>
</el-tree>
handleCheckChange(data, checked) {
this.tags.push(data.tenantName)
//获取所有选中的节点id
this.tenantUserId = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())
console.log(this.tenantUserId, '选中的节点')
this.checked = checked
// 该节点未选中的时候
for (var i = 0; i <= this.tags.length; i++) {
if (this.checked == false) {
this.tags.splice(this.tags.indexOf(this.i), 1)
}
}
}
即使某条数据被取消选择后,获取的也是当前被选中的节点id