利用本地地图json文件储存省市区信息
json文件来源 https://pan.baidu.com/s/1g-BitDJ5wld1UgHhiHjcFA 密码:s1lb
vue文件
<template>
<div class="linkage">
<div>
<el-select v-model="selectProvince" filterable size="small" value-key="areacode" @change="selectProvinceFun($event)" placeholder="请选择省份">
<!-- <el-option value="" label="请选择省份"></el-option> -->
<el-option :value="item" :label="item.areaname" v-for="item in city" :key="item.areacode"></el-option>
</el-select>
</div>
<div>
<el-select v-model="selectCity" filterable size="small" value-key="areacode" @change="selectCityFun($event)" placeholder="请选择城市">
<!-- <el-option value="" label="请选择城市"></el-option> -->
<el-option :value="item" :label="item.areaname" v-for="item in cityList" :key="item.areacode"></el-option>
</el-select>
</div>
<div>
<el-select v-model="selectArea" filterable size="small" value-key="areacode" @change="selectAreaFun($event)" placeholder="请选择区县">
<!-- <el-option value="" label="请选择区县"></el-option> -->
<el-option :value="item" :label="item.areaname" v-for="item in areaList" :key="item.areacode"></el-option>
</el-select>
</div>
</div>
</template>
<script>
//引用地图json文件
import city from '@/assets/json/city.json'
export default {
name: 'linkage',
data () {
return {
// 整个省市县数据
city: city,
// 被选中的市数据
cityList: [],
// 被选中的县数据
areaList: [],
selectProvince: '',
selectCity: '',
selectArea: ''
}
},
mounted () {
},
methods: {
// 省份 市 县联动
selectProvinceFun (event) {
console.log(event)
if (event) {
this.cityList = event.subarea
} else {
this.cityList = []
}
this.areaList = []
// this.$emit('getLawyerListInfo', [event.areaname, 'province'])
this.selectProvince=event.areaname
this.$forceUpdate();
},
selectCityFun (event) {
console.log(event)
if (event) {
this.areaList = event.subarea
} else {
this.areaList = []
}
// this.$emit('getLawyerListInfo', [event.areaname, 'city'])
this.selectCity=event.areaname
this.$forceUpdate();
},
selectAreaFun (event) {
console.log(event)
// this.$emit('getLawyerListInfo', [event.areaname, 'area'])
this.selectArea=event.areaname
this.$forceUpdate();
}
}
}
</script>
<style>
.linkage{
display: flex;
}
.linkage div{
margin-right: 5px;
}
</style>