<!-- 必须属性: default-expanded-keys node-key
default-expanded-keys 设置默认展开的数组
-->
<el-tree :default-expanded-keys='idArr' node-key="id" :data="orgtree" :props="defaultProps" @node-click="handleNodeClick" highlight-current ></el-tree>
data() {
return {
defaultProps: {
children: "children",
label: this.labelFn
},
orgtree: [],
idArr:[]
};
methods:{
getOrgTree() {
get("地址").then(res => {
this.orgtree = res.data.data;
//将第一级的id push进数组
this.orgtree.forEach(item=>{
this.idArr.push(item.id)
})
//将第二级的id push进数组
if(this.orgtree[0].children.length>0){
this.orgtree[0].children.forEach(item=>{
this.idArr.push(item.id)
})
}
});
},
}