elementui elcascader懒加载

 1 地理位置懒加载;
 2 <el-cascader
 3 ref="cascaderLoc"
 4 @visible-change="changeBgClass"
 5 v-model="form.assetLoc"
 6 :option="optionsAssetLoc"
 7 :props="locationProp"
 8 emitPayh="true"
 9 @change="getLocNodes"
10 filyerable
11 clearable
12 >
13 </el-cascader>
14 2.data中配置
15 optionsAssetLoc:[],
16 locationProps:{
17     checkStrictly:true,//严格遵循父子节点互不关联
18     value:"value",
19     lazy:true,
20     lazyLoad:function lazyLoad(node,resolve){
21                 const{data,level,path}=node;
22                 if(!data||(data&&data.haschild==false)||(data&&data.leaf==true)){
23                   return resolve([])
24                }
25                 let code=data.value;
26                 //调用请求获取数据
27                 this.vm.getLocationOption(code,path,node).then(
28                     {resolve(res)}
29                 )
30 
31    }.bind(this)
32 }
33 created(){
34     this.getLocationOption();
35 }
36 methods:{
37     getLocationOption(code,path,node){
38         return new Promise(resolve,reject){
39             let param {code:code||"",async:false};
40             thisObj.callAPIcom(url,param,"post",res=>{
41                 if(res&&res.resp.code==0){
42                      if(this.optionAssetLoc.length==0){
43                          res.data[0].locData[0].children=[];
44                          this.optionAssetLoc=res.data[0].locData;
45                      }else{
46                                   let result=res.data[0].locData[0];
47                                   if(result.children.length==0){
48                                        this.$refs.cascaderLoc.dropDowVisible=false;
49                                   }
50                                   resolve(result.children)
51                              }
52                  }
53             })
54         }
55 
56     }
57 
58 
59 
60 
61 
62 
63 }            
View Code

 

 1 地理位置懒加载;
 2 <el-cascader
 3 ref="cascaderLoc"
 4 @visible-change="changeBgClass"
 5 v-model="form.assetLoc"
 6 :option="optionsAssetLoc"
 7 :props="locationProp"
 8 emitPayh="true"
 9 @change="getLocNodes"
10 filyerable
11 clearable
12 >
13 </el-cascader>
14 2.data中配置
15 optionsAssetLoc:[],
16 locationProps:{
17     checkStrictly:true,//严格遵循父子节点互不关联
18     value:"value",
19     lazy:true,
20     lazyLoad:function lazyLoad(node,resolve){
21                 const{data,level,path}=node;
22                 if(!data||(data&&data.haschild==false)||(data&&data.leaf==true)){
23                   return resolve([])
24                }
25                 let code=data.value;
26                 //调用请求获取数据
27                 this.vm.getLocationOption(code,path,node).then(
28                     {resolve(res)}
29                 )
30 
31    }.bind(this)
32 }
33 created(){
34     this.getLocationOption();
35 }
36 methods:{
37     getLocationOption(code,path,node){
38         return new Promise(resolve,reject){
39             let param {code:code||"",async:false};
40             thisObj.callAPIcom(url,param,"post",res=>{
41                 if(res&&res.resp.code==0){
42                      if(this.optionAssetLoc.length==0){
43                          res.data[0].locData[0].children=[];
44                          this.optionAssetLoc=res.data[0].locData;
45                      }else{
46                                   let result=res.data[0].locData[0];
47                                   if(result.children.length==0){
48                                        this.$refs.cascaderLoc.dropDowVisible=false;
49                                   }
50                                   resolve(result.children)
51                              }
52                  }
53             })
54         }
55 
56     }
57 
58 
59 
60 
61 
62 
63 } 
posted @ 2020-09-06 20:03  努力~努力再努力~  阅读(3734)  评论(0编辑  收藏  举报