First call the tree control in element:
<el-tree
:data="dataTree"
ref="tree"
:props="props"
accordion
show-checkbox
node-key="id"
updateKeyChildren=""
@check-change="handleCheckChange"
>
</el-tree>
Then use the @check-change event to get the callback when the selected state of the node changes
// 树形方法_复选框
handleCheckChange(data) {
console.log(data)
debugger;
// 选中当前子节点以及父节点
let res = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())
console.log(res)
}
The res returns here are the child nodes you click and the callback when the parent node changes.
The realization of echo
first give a button
<el-button
type="text"
size="small"
@click="updateHandle(scope.row)"
>
Get the content of this row through scope.row, and then get the permission id you already have
updateHandle(data) {
console.log(data);
// window.location.reload()
if (data.menuIds) {
var tempArr = data.menuIds.split(","); //用,分割
this.defaultCheck = tempArr; //创建一个空数组来接受tempArr
this.$refs.tree.setCheckedKeys(this.defaultCheck) //实现回显
// this.defaultCheck = Object.assign([], this.defaultCheck, tempArr);
}
},