element tree树形懒加载


                
                  
                    {{ node.label }}
                  
                
              
import { getdeptlist,getuserlist} from "../api/home";

data(){
   return:{
          defaultProps: {
        children: "zones",
        label: "abbrname",
        isLeaf: "leaf",
      },
  }
}
method:{
        async loadNode(node, resolve) {
      let that = this;
      if (node.level === 0) {
        let arr = await that.getdatalist();
        return resolve(arr);
      }
      if (node.level >= 1) {
        let arr1 = await that.getChildByList(node.data.id, resolve);
        return resolve(arr1);
      }
    },
    //获取树形图
    async getdatalist() {
      let res = await getdeptlist({deptid:''});
      if (res.code == 200) {
        let data = res.data;
        data.forEach((item) => {
          item.parentid = item.parentid;
          item.id = item.id;
          item.isLeaf = true;
        });
        return data;
      }
      return [];
    },
    async getChildByList(_parentID) {
      // 获取子节点请求
      let params={
          deptid:_parentID
      }
      let res = await getdeptlist(params);
      if (res.code == 200) {
        let data = res.data;
        data.forEach((item) => {
          item.parentid = item.parentid;
          item.id = item.id;
          item.isLeaf = false;
        });
        return data;
      }
      return [];
    },
}

你可能感兴趣的:(element tree树形懒加载)