element-ui 캐스케이드 선택 지역

1830 단어 vuejs
//   prop  
   props:{
    label: 'areaName',
    value: 'areaId',
    //children: 'children',
   },


//     
getProvence() {
  post(url, {parentId: 0}).then((res) => {
    this.addressObject.list = res && res.data || []
    this.addressObject.list.forEach((item,index)=>{
      this.$set(this.addressObject.list[index], 'children', [])
    })

  })
},
//      
handleAddressChange(val) {
  if(val.length <= 0 ) return;
  let provinceList = this.addressObject.list;
  let provinceLength = provinceList.length;
  let provinceAreaId = val[0];

  if(val.length === 1)  {
     //  areaId,          
    post(url, {parentId: provinceAreaId}).then((res) => {
      for(let i = 0; i < provinceLength; i++) {
        if(provinceList[i].areaId === provinceAreaId) {
          this.$set(provinceList[i], 'children', res && res.data  || []);
          provinceList[i].children.forEach((item,index)=>{
             this.$set(provinceList[i].children[index], 'children', [])
          })
          break;
        }
      }
    })
  }
  if(val.length === 2)  {
    let cityId = val[1]; //  areaId,         
    post(url, {parentId: cityId}).then((res) => {
      for(let i = 0; i < provinceLength; i++) {
        if(this.addressObject.list[i].areaId === provinceAreaId) {
          let findProvince = this.addressObject.list[i];
          let cityList = findProvince.children;
          let cityLength = cityList.length;
          for(let j = 0; j < cityLength; j++){
              if(cityList[j].areaId === cityId) {
                this.$set(cityList[j], 'children', res && res.data  || []);
                break;
              }//if
          }//for
          break;
        }//if
      }//for
    })
  }
},

좋은 웹페이지 즐겨찾기