当前位置:   article > 正文

element-ui 级联选择Cascader选择省市区_ele 级联省市区

ele 级联省市区
// 设置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
    })
  }
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/118965
推荐阅读
相关标签
  

闽ICP备14008679号