<el-form-item label="省">
<el-select v-model="form.province" @change="gengxin1">
<el-option v-for="item in address" :value="item.sheng">{{item.sheng}}</el-option>
</el-select>
</el-form-item>
<el-form-item label="市">
<el-select v-model="form.city" @change="gengxin2">
<el-option v-for="item in citys" :value="item.shi">{{item.shi}}</el-option>
</el-select>
</el-form-item>
<el-form-item label="县">
<el-select v-model="form.county">
<el-option v-for="item in countys" :value="item">{{item}}</el-option>
</el-select>
</el-form-item>
import address from '@/assets/json/address'//建议放在assets文件夹下 | address.json(下面有链接)
data() {
return {
address: address,
citys: [],
countys: []
}
}
gengxin1() {
const _this = this
_this.address.forEach(function(item,index) {
if (item.sheng === _this.form.province) {
_this.citys = item.city
}
})
_this.form.city = _this.citys[0].shi
this.gengxin2()
},
gengxin2() {
const _this = this
_this.citys.forEach(function(item,index) {
if (item.shi === _this.form.city) {
_this.countys = item.qx
}
})
_this.form.county = _this.countys[0]
}
json数据
https://hakupload.oss-cn-beijing.aliyuncs.com/Mabatis-plus/json/address.json
json数据来着:https://www.cnblogs.com/z-hj/p/12963460.html