Element中怎么实现一个树形控件-成都快上网建站

Element中怎么实现一个树形控件

Element中怎么实现一个树形控件,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

东平网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联从2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

1.前端布局


    
        
            
                
                    
                        
                    
                
                
            
        
        
            
                
                    
                        
                            
                        
                        
                            搜索
                        
                    
                
                
                  
                  
                  
                  
                  
                  
                
                
                
                  
                  
                  
                  
                  
                  
                
            
        
     
    new Vue({         el: '#home',         data: {             bkTopoData: [                 {                     bk_inst_name: '一级 1',                     child: [                         {                             bk_inst_name: '二级 1-1',                             child: [                                 {                                     bk_inst_name: '三级 1-1-1'                                 }                             ]                         }                     ]                 },                 {                     bk_inst_name: '一级 2',                     child: [                         {                             bk_inst_name: '二级 2-1',                             child: [                                 {                                     bk_inst_name: '三级 2-1-1'                                 }                             ]                         },                         {                             bk_inst_name: '二级 2-2',                             child: [                                 {                                     bk_inst_name: '三级 2-2-1'                                 }                             ]                         }                     ]                 },                 {                     bk_inst_name: '一级 3',                     child: [                         {                             bk_inst_name: '二级 3-1',                             child: [                                 {                                     bk_inst_name: '三级 3-1-1'                                 }                             ]                         },                         {                             bk_inst_name: '二级 3-2',                             child: [                                 {                                     bk_inst_name: '三级 3-2-1'                                 }                             ]                         }                     ]                 }             ],             setProps: {                 children: 'child',                 label: 'bk_inst_name'             },             searchBkId:'',             searchContent:'',             bkBizData:[],             tableData:[],             hostData: []         },         mounted() {             this.init()         },         methods: {             init() {                 axios.get(site_url + "get_biz_list/").then(res => {                     if (res.data.result){                         this.bkBizData = res.data.data;                     }else{                         this.$message.error('获取业务失败');                     }                 },'json');             },             handleNodeClick(data) {                 axios.post(site_url + "search_host/", data).then(res => {                     if (res.data.result) {                         this.hostData = res.data.data;                     } else {                         this.$message.error('获取主机失败');                     }                 }, 'json');             },             bizChange() {                 axios.get(site_url + "get_bk_topo/?bk_biz_id=" + this.searchBkId).then(res => {                     if (res.data.result){                         this.bkTopoData = res.data.data;                     }else{                         this.$message.error('获取业务失败');                     }                 },'json');             },             search() {                 console.log("aaa")             }         }     })

2.后端接口

from django.views.decorators.csrf import csrf_exempt

def get_bk_topo(request):
    bk_biz_id = request.GET.get("bk_biz_id")
    res_data = cc_search_biz_inst_topo(request, bk_biz_id)
    return JsonResponse({"result": True, "data": res_data})

def get_biz_list(request):
    fields = ["bk_biz_id", "bk_biz_name"]
    data = cc_search_business(fields)
    return JsonResponse({"result": True, "data": data})

def search_host(request):
    res_data = []
    data = json.loads(request.body)
    bk_obj_id = data.get("bk_obj_id")
    bk_inst_id = data.get("bk_inst_id")
    host_data = cc_search_host(request, bk_obj_id, bk_inst_id)
    for h in host_data:
        bk_host_name = h.get("host", {}).get("bk_host_name")
        bk_os_name = h.get("host", {}).get("bk_os_name")
        bk_cloud_id = h.get("host", {}).get("bk_cloud_id")[0].get("bk_inst_id")
        bk_cloud_name = h.get("host", {}).get("bk_cloud_id")[0].get("bk_inst_name")
        bk_host_id = h.get("host", {}).get("bk_host_id")
        bk_host_innerip = h.get("host", {}).get("bk_host_innerip")
        res_data.append({
            "bk_host_name": bk_host_name,
            "bk_os_name": bk_os_name,
            "bk_cloud_id": bk_cloud_id,
            "bk_cloud_name": bk_cloud_name,
            "bk_host_id": bk_host_id,
            "bk_host_innerip": bk_host_innerip,
        })
    return JsonResponse({"result": True, "data": res_data})

实现效果Element中怎么实现一个树形控件

看完上述内容,你们掌握Element中怎么实现一个树形控件的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


新闻标题:Element中怎么实现一个树形控件
网页路径:http://kswjz.com/article/jgeocg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流