<!-- 必須屬性: 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)
})
}
});
},
}