In el-Tree, there is an obvious gap in the output data. As long as the output data contains the id of the parent, the check effect of the parent is all, regardless of whether the children under the current parent are partially selected or all selected. Expected renderings:Actual renderings:I’ve seen a lot of bloggers talk about using the setChecked loop to check the leaves conveniently, but I’ve tried setTimeout, nextTick, and it doesn’t work. So write your own. I’m still using setCheckedKeys to do that, and the logic is pretty simple,arrIs an array of leaf nodes. usinggetNode()Get the current node, loop through the data returned to me at the end of the segment to determine whether the current node is a leaf or not, and whether it is savedarrIn the middle. In the usesetcheckedKey(arr)Back and forth display data, so that you can achieve the parent half – selected state.

const arr = []
res.data.forEach(f= >{
	if(!this.$refs.tree.getNode(f.permissionId).childNodes || !this.$refs.tree.getNode(f.permissionId).childNodes.length) {
       arr.push(f.permissionId)
     }
})
this.$refs.tree.setCheckedKeys(arr)
Copy the code