<el-tree :props="props" ref="treeList" :load="loadNode" check-strictly show-checkbox node-key='id' @check ='changetree' @check-change="handleCheckChange"> </el-tree> handleCheckChange(data, checked, tree) { if (checked) { this.currentNodeData.id = data.id this.$refs.treeList.setCheckedNodes([data.id]) } }, changetree(data,lst) { if(lst,checkedKeys.lenght==0) this.$refs.treeList.setCheckedNodes([data.id]) }
说明,一定存在node-key值,并且通过ref定位到具体树进行赋值。
其他可用函数说明:
this.$refs.treeList.getCheckedNodes();获取选中节点数据
this.$refs.treeList.getCheckedKeys();获取所有所选节点的主键ID数组
this.$refs.treeList.setCheckedKeys([data.id]);给选定节点的主键ID数组,树节点会勾选