怠惰ロードツリー、親ノードがチェックされ、子ノードが怠惰ロードされた後もチェックされます.
11698 ワード
<template>
<div class="deptTree">
<el-button
@click="test"
>
</el-button>
<!-- \ \ -->
<el-tree
ref="tree"
show-checkbox
accordion
:load="handleLoad"
lazy
node-key="id"
:default-expanded-keys="[rootNode.id]"
:default-checked-keys="[]"
:props="defaultProps"
:expand-on-click-node="true"
:highlight-current="true"
:default-expand-all="false">
</el-tree>
</div>
</template>
<script>
export default {
name: "deptTree",
data(){
return {
defaultProps: {
children: 'children',
label: 'label'
},
content:'',
treeData:[],
rootKey:'00000002',
rootNode : {
id : "00000002",
label : " "
},
checkedKeys : []
}
},
methods: {
/**
*
*/
handleLoad(node, resolve) {
// key,
if(this.$refs.tree!=undefined) this.checkedKeys = this.$refs.tree.getCheckedKeys();
if (node.level == 0) {
return resolve([this.rootNode]);
} else {
var children = [
{
id : "00000003",
label : " 1"
},
{
id : "00000004",
label : " 2"
},
{
id : "00000005",
label : " 3"
}
];
resolve(children);
}
if(this.$refs.tree!=undefined) this.$refs.tree.setCheckedKeys(this.checkedKeys);
},
test() {
var checkedKeys = this.$refs.tree.getCheckedKeys();
console.log(checkedKeys);
}
},
}
</script>
<style scoped lang="scss">
</style>
<style lang="scss">
</style>