problem description
I used lazy loading rendering el-tree
after the operation corresponding node-key= "districtId" to add new child nodes to delete nodes under the corresponding nodes. By requesting to add and delete manual refreshes, you can see how the changes are done (after adding and deleting data). Dynamic changes el-tree
< el-tree
:props="defaultProps"
:load="loadNode"
node-key="districtId"
ref="tree"
:default-expanded-keys="["-1"]"
:default-checked-keys="["1086"]"
:expand-on-click-node="false"
highlight-current
@node-click="handleNodeClick"
lazy>
</el-tree>
getManageList(node,resolve,initFirst) {
let obj = {};
if (node && node.data) {
obj.id = node.data.districtId;
}else{
obj.id = this.id;
}
API.administrativeArea(obj).then(res => {
if (res.status === 0) {
let temp = [];
if (initFirst) {
temp.push({
districtCode: res.data.parentDto.districtCode,
districtName: res.data.parentDto.districtName + ((res.data.parentDto.count === 0)?"":(" "+",("+res.data.parentDto.count+")")) ,
districtId: res.data.parentDto.districtId,
districtLevel: res.data.parentDto.districtLevel,
count: res.data.parentDto.count,
leaf: res.data.parentDto.count === 0
});
resolve(temp);
} else {
let children = [];
res.data.districtCountList.map(item => {
children.push({
districtCode: item.districtCode,
districtName: item.districtName + ((item.count === 0)?"":(" "+",("+item.count+")")),
districtId: item.districtId,
districtLevel: item.districtLevel,
count: item.count,
leaf: item.count === 0
});
});
resolve(children);
}
}
});
},
//
loadNode(node, resolve) {
if (node.level === 0) {
this.getManageList(node,resolve,true);
} else if (node.level >= 1) {
this.getManageList(node,resolve);
}
},
//
handleNodeClick(data) {
console.log(data);
let obj = {};
obj.id = data.districtId;
this.districtId = data.districtId;
this.getList();
},