这是我的单选树,是那种懒加载的树,因为Element-UI没有参数设置单选数,我们需要自己改动相应的逻辑。话不多说直接上代码
<el-tree ref="tree" :props="props" node-key='departID' :load="loadNode" @check='clickbox' :check-strictly='true' lazy
show-checkbox>
</el-tree>
clickbox(node, tree) {
if (tree.checkedKeys.length == 0) {
this.$refs.tree.setCheckedKeys([]);
this.node = node;
this.nodeisChecked = false;
} else {
this.$refs.tree.setCheckedKeys([]);
this.$refs.tree.setCheckedKeys([node.departID]);
this.node = node;
this.nodeisChecked = true;
}
}
this.node就是你树的节点。
this.nodeisChecked就是当前节点是否选中。