首页 > 其他分享 >vue +iview Select省市区联动

vue +iview Select省市区联动

时间:2022-09-21 10:24:52浏览次数:64  
标签:city vue cityList area res id any Select iview

因为需要保存的表里只有City_id一个字段,所以这边只保存"区"的值
<Row type="flex" justify="start" class="code-row-bg" v-show="loginName=='admin'">
        <Col span="8">
          <FormItem label="省 :" style="width: 100%">
            <Select v-model="BaseAreaProvince"  style="width:150px" @on-change="selectProvince">
                <Option v-for="(Province,provinceIndex) in provinceList" :value="Province.id" :key="provinceIndex">{{ Province.area_name }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="市 :" style="width: 100%">
            <Select v-model="BaseAreaCity" style="width:150px"  @on-change="selectcity">
              <Option v-for="city in cityListShow" :value="city.id" :key="city.id">{{ city.area_name }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="区 :" style="width: 100%">
            <Select v-model="BaseArea" style="width:140px" @on-change="selectArea">
                <Option v-for="area in areaListShow" :value="area.id" :key="area.id">{{ area.area_name }}</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row>



Js部分:

BaseAreaProvince: string = '';
 BaseAreaCity: string = '';
  BaseArea: string = '';

city_id:any; 存储需要保存到表里的"区"的数据
provinceList:any=[];
cityList:any=[];
cityListShow:any=[];//显示在页面的List
areaListShow:any=[];//显示在页面的List
areaList:any=[];
visibleChange(value: boolean) {
this.provinceList=[];
this.cityList=[];
this.areaList=[];
this.getProvinces();
this.getCityList();
this.getAreaList(); }
getProvinces(){
this.$store.dispatch({
type: "basearea/getBaseArea",
data:{area_level:1} })
.then((res)=>{
this.provinceList= res.items;
});
}
getCityList(){
this.$store.dispatch({
type: "basearea/getBaseArea",
data:{area_level:2} })
.then((res)=>{
this.cityList= res.items;
});
}
getAreaList(){
this.$store.dispatch({
type: "basearea/getBaseArea",
data:{area_level:3} })
.then((res)=>{
this.areaList= res.items;
});
}
//选择省
selectProvince(e){
this.cityListShow= this.cityList.filter((item) => item.parent_id == e);
this.BaseAreaCity = this.cityListShow[0].value; this.BaseArea='';
}
//选择市
selectcity(e){
this.areaListShow= this.areaList.filter((item) => item.parent_id == e);
if(this.areaListShow.length>0){
this.BaseArea = this.areaListShow[0].value; }
}
//选择区 selectArea(e){
this.city_id=e;
}
save() {     (this.$refs.TechnicianForm as any).validate(async (valid: boolean) => {       if(this.city_id>0){         this.Technician.city_id=this.city_id; //Technician为模型类       }     });   }
如果有更优化的方案,烦请指导

 

标签:city,vue,cityList,area,res,id,any,Select,iview
From: https://www.cnblogs.com/QiangQiangDai/p/16714658.html

相关文章

  • vue下载图片
       asyncworks(obj){   awaitthis.axios({    method:'get',    url:`entryFormController/downloadWork.do`,    param......
  • vue导出文件
    /**导出*/asynctoExcel(){//letresult=awaitthis.axios({//method:'get',//url:`issdc-manage/gameController/export.do`,......
  • vue上传证书
       //队伍证书上传getFile(){varthat=this;////1创建formDataletformData=newFormData();////2添加数据,key可以......
  • vue多图片上传组件
         <template><!--上传控件用法:<upload-widgetv-model="imgUrl"></upload-widget>--><divclass="clearfix"><a-upload......
  • Vue中使用js-audio-recorder实现录音时提示:浏览器不支持getUserMedia!
    场景Vue中使用js-audio-recorder插件实现录音功能并实现上传Blob数据到SpringBoot后台接口:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/126957202上面......
  • Vue 组合式函数简介
    Vue组合式函数:export导出一个函数。函数内可以定义生命周期勾子、数据及方法,它是可复用的模块。类似Mixin混入。但比Mixin更有优势。组合式函数示例:useDemo.js impo......
  • 为什么使用 Pinia(Vuex)
    Pinia定义Pinia(Vuex?)是一个独立于组件的全局状态,每一个组件都可以读取和写入。Pinia有三个重要的概念:state、getters、actions。state等价于组件中的data、getters......
  • VueRouter 报错:inject() can only be used inside setup() or functional components
    单独创建的一个文件,封装了登录函数的业务逻辑,出现了一个警告,紧接着就是报错:说不能读取到路由的push函数。路由必须在组件里面使用,不能在ts或js文件中使用。还要注......
  • Vue3:Teleport
    TeleportVue鼓励我们通过将UI和相关行为封装到组件中来构建UI。我们可以将它们嵌套在另一个内部,以构建一个组成应用程序UI的树。然而,有时组件模板的一部分逻辑上属......
  • Vue3:状态驱动的动态 CSS
     状态驱动的动态CSS单文件组件的<style>标签可以通过v-bind这一CSS函数将CSS的值关联到动态的组件状态上 <template><divclass="box1">hello</div>......