插件安装
npm install element-china-area-data -S
效果

JS代码

import {regionData} from 'element-china-area-data'`
let form = reactive({
  catteryName: '',
  ownerName: '',
  province: {
    value: '',
    label: '',
    children: []
  },
  city: {
    value: '',
    label: '',
    children: []
  },
  area: '',
  catteryRegisterAddr: '',
  email: '',
  tel: '',
  catteryIntroduction: '',
})
//切换省份函数
const handleProvinceSelect = () => {
  form.city.value = ''
  form.area = ''
  cityList.value = form.province.children
}
//切换城市函数
const handleCitySelect = () => {
  form.area = ''
  areaList.value = form.city.children
}
//切换地区函数
const handleAreaSelect = () => {

}
//二级城市列表
const cityList = ref([])
//三级地区列表
const areaList = ref([])

页面部分代码

<el-form-item label="城市">
      <el-select v-model="form.province" placeholder="请选择省" class="ms-2" @change="handleProvinceSelect">
        <el-option
            v-for="item in regionData"
            :key="item.value"
            :label="item.label"
            :value="item">
        </el-option>
      </el-select>
      <el-select v-model="form.city" placeholder="请选择市" :disabled="!form.province || cityList.length == 0"
                 @change="handleCitySelect" class="ms-2">
        <el-option
            v-for="item in cityList"
            :key="item.value"
            :label="item.label"
            :value="item">
        </el-option>
      </el-select>
      <el-select v-model="form.area" placeholder="请选择区"
                 :disabled="!form.province || !form.city || areaList.length == 0" @change="handleAreaSelect"
                 class="ms-2">
        <el-option
            v-for="item in areaList"
            :key="item.value"
            :label="item.label"
            :value="item">
        </el-option>
      </el-select>
    </el-form-item>
Logo

前往低代码交流专区

更多推荐