HTML
<el-button type="primary" @click="clear">重置</el-button>
<el-tree
node-key="id"
show-checkbox
:data="deptOptions"
:props="defaultProps"
:expand-on-click-node="false"
accordion
ref="tree"
:check-on-click-node="true"
@check="handleCheckChange"
/>
js
methods:{
clear(){
this.$nextTick(() => {
this.$refs.tree.setCheckedKeys([])
});
}
}
常见报错
原因: 缺node-key:每个树节点用来作为唯一标识的属性,整棵树应该是唯一的