• 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
  • 相关阅读:
    百度地图划区测量获取坐标
    【pytest官方文档】解读- 如何安装和使用插件
    Linux设备树学习(二)设备树的解析
    Java项目:ssm汽车租赁系统设计
    网络编程套接字 | TCP套接字
    基于Linux系统聊天室增加数据库sqlite功能实现(08)
    vtk- 数据类型(一) 三角链实例代码
    机器学习基础:参数估计与假设检验
    【NVMe2.0b 14】NVMe Admin Command Set
    mysql面试题30:什么是数据库连接池、应用程序和数据库建立连接的过程、为什么需要数据库连接池、你知道哪些数据库连接池
  • 原文地址:https://blog.csdn.net/qq_44783880/article/details/126014250