首页 > 其他 > 详细

vue elementui el-cascader级联选择器没子级时出现暂无数据问题

时间:2021-04-20 20:59:26      阅读:646      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 原因时没有子级的时候后台返回了一个空数字  例如: children:[ ]

这时候需要递归将children为空的赋值为undefined

技术分享图片

 

 

//获取系统分类管理列表
    getSystemTypeApi(){
      getSystemTypeApi({}).then((res)=>{
        if(res.data.code == 200){
          this.systemTypeList = this.getTreeData(res.data.data);
          // this.systemTypeList = res.data.data;
        }
      });
    },
    // 递归判断列表,把最后的children设为undefined
    getTreeData(data){
      for(var i=0;i<data.length>0;i++){
        if(data[i].children == null||data[i].children.length<=0){
          // children若为空数组,则将children设为undefined
          data[i].children = undefined;
        }else {
          // children若不为空数组,则继续 递归调用 本方法
          this.getTreeData(data[i].children);
        }
      }
      return data;
    },

 

vue elementui el-cascader级联选择器没子级时出现暂无数据问题

原文:https://www.cnblogs.com/web-aqin/p/14681979.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!