• vue中省市区


    :load-data="loadData"指:从后端查询出的全部的省市区数据

     loadData(item, callback) {
          item.loading = true
          if (item.flag === 0) {
            let url = '/listCityByProvinceCode'
            this.$get(
                url,
                { provinceCode: item.value },
                (res) => {
                  let result = res.data
                  if (result.status == 200) {
                    let data = result.data
                    for (let i in data) {
                      let city = {}
                      city.label = data[i].cityName
                      city.value = data[i].cityCode
                      city.flag = 1
                      if (item.value != '820000') {
                        city.children = []
                        city.loading = false
                      }
                      item.children.push(city)
                    }
                    callback()
                    item.loading = false
                  } else {
                    this.$toast(result.msg)
                  }
                },
                (err) => {
                  this.$hideMark()
                  this.$toast(this.networkerr)
                  item.loading = false
                }
            )
          }
    
          if (item.flag === 1) {
            let url = '/listAreaByCityCode'
            this.$get(
                url,
                { cityCode: item.value },
                (res) => {
                  let result = res.data
                  if (result.status == 200) {
                    let data = result.data
                    for (let i in data) {
                      let city = {}
                      city.label = data[i].areaName
                      city.value = data[i].areaCode
                      // city.children = [];
                      // city.loading = false;
                      city.flag = 2
                      item.children.push(city)
                    }
                    callback()
                    item.loading = false
                  } else {
                    this.$toast(result.msg)
                  }
                },
                (err) => {
                  this.$hideMark()
                  this.$toast(this.networkerr)
                  item.loading = false
                }
            )
          }
        },
    
    • 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
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68

    :data="cityData"指:
    cityData=[],
    //获取省份列表
    listProvince() {
    let url = ‘/listProvince’
    this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … this.toast(result.msg)
    }
    },
    (err) => {
    this. h i d e M a r k ( ) t h i s . hideMark() this. hideMark()this.toast(this.networkerr)
    }
    )
    },
    @on-change=“cityChange”:选择省市区这个动作

        cityChange(value, selectedData) {
          //let regionId=this.formValidate.regionFlag;
          this.provinceCodeId = selectedData[0].value
          console.log(selectedData)
          console.log(selectedData[0].value)
          console.log(selectedData.length)
          //this.formValidate.cityData2=selectedData;
          this.cityMsg = ''
          if (selectedData != null && selectedData.length > 0) {
            for (let i in selectedData) {
              if (i == 0) {
                this.formData.province = selectedData[0].value
              }
              if (i == 1) {
                this.formData.city = selectedData[1].value
              }
              if (i == 2) {
                this.formData.area = selectedData[2].value
              }
            }
          }
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    v-model=“formData.cityData2”:选择好绑定的省市区参数

     <Row :gutter="16">
                  "12">
                  "省/市/区" prop="cityData2">
                   <Cascader
                           :data="cityData"
                           v-model="formData.cityData2"
                           @on-change="cityChange"
                           filterable
                           :clearable=false
                           :load-data="loadData"
    
                   >
                 
                  
                  
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
  • 相关阅读:
    DDOS原理以及解决方案!
    经典OJ题:单链表相交
    halcon模板匹配捆绑测量矩形检测芯片针脚
    台灯哪种灯光对眼睛好?分享专业护眼的LED灯
    【E题】2023年电赛运动目标控制与自动追踪系统方案
    开源六轴机械臂myCobot 280末端执行器实用案例解析
    Hive默认分割符、存储格式与数据压缩
    3D打印机的使用教程( 超详细 )
    SpringBoot 工程打包并运行
    Sprin、SpringBoot、微服务的概念
  • 原文地址:https://blog.csdn.net/qq_44783880/article/details/126014250