Primero llame al control de árbol en el elemento:
<el-tree
:data="dataTree"
ref="tree"
:props="props"
accordion
show-checkbox
node-key="id"
updateKeyChildren=""
@check-change="handleCheckChange"
>
</el-tree>
Luego use el evento @ check-change para obtener la devolución de llamada cuando cambie el estado seleccionado del nodo
// 树形方法_复选框
handleCheckChange(data) {
console.log(data)
debugger;
// 选中当前子节点以及父节点
let res = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())
console.log(res)
}
Las res devoluciones aquí son los nodos secundarios en los que hace clic y la devolución de llamada cuando cambia el nodo principal.
La realización del eco
primero dale a un botón
<el-button
type="text"
size="small"
@click="updateHandle(scope.row)"
>
Obtenga el contenido de esta fila a través de scope.row, y luego obtenga el ID de permiso que ya tiene
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);
}
},