因为需要保存的表里只有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为模型类
      }
    });
  }
如果有更优化的方案,烦请留言指导

vue +iview Select省市区联动的更多相关文章

  1. vue iview Select bug,在低版本浏览器中报错

    iview是个好东西,今天第一次试用,用来做了一个app,但是在安卓5.1各种报错啊,头痛的是不知道具体哪行代码错了,总是报错undefined is not a function. 倒腾了半天,原来 ...

  2. vue+iview多条联动,for循环data是函数

    问题:多条for循环出的数据二级联动for循环出多条数据,每条数据都有一个二级联动,每次下拉一级联动,二级的选项都是变化的. 思考刚开始一直想不出如何实现二级联动下拉的数据动态变化,因为之前一直都是v ...

  3. JS省市区联动

    JS省市区使用文档 一:服务器返回JSON格式要求如下网址里面data的格式:(拿KISSY组件data格式来做的) http://gallery.kissyui.com/cityselector/d ...

  4. JS省市区联动效果

    省市区联动下拉效果在WEB中应用非常广泛,尤其在电商网站最为常见.一般使用Ajax实现无刷新下拉联动.利用jQuery,通过读取JSON数据,实现无刷新动态下拉省市二(三)级联动效果. 首先我们可以看 ...

  5. 基于AngularJs + Bootstrap + AngularStrap 省市区联动实践

    什么是 AngularJs?网上一大堆资料,没能真正说明白. AngularJs 就是一个函数库,算不上一个框架,源码2万2千多行,提供了前端MVC的开发方式, 有双向绑定,指令等特性,这是具有革命性 ...

  6. uniapp自定义简单省市区联动组件

    又双叒一个uniapp组件 最近有一个选择地址的需求,就写了一个省市区联动选择器. 选择日期使用的picker,就照着它简单的整了一个,使用网络请求城市数据,还用到了vuex组件数据共享. 本来自己整 ...

  7. 简单jquery实现select三级联动

    简单的jquery实现select三级联动 代码如下: <!DOCTYPE html> <html> <head> <meta charset="u ...

  8. SharePoint 2010 自定义 字段 类型--------省市区联动

    转:http://www.cnblogs.com/sp007/p/3384310.html 最近有几个朋友问到了有关自定义字段类型的问题,为了让更多的人了解自定义字段类型的方法,特写一篇博客与大家分享 ...

  9. thinkphp5+vue+iview商城 公众号+小程序更新版本

    thinkphp5+vue+iview商城加分销 源码下载地址:http://github.crmeb.net/u/crmeb 演示站后台:http://demo25.crmeb.net 账号:dem ...

  10. vue & iview

    vue & iview ui components https://codepen.io/webgeeker/pen/EJmQxQ https://www.iviewui.com/docs/g ...

随机推荐

  1. h5:vue3 + ts + vite + vuex + axios + vant4 + scss + postcss+mockjs+element-plus

    模板地址:https://gitee.com/zhang_meng_lei/mobile-template-h5-vue3/tree/master 1.安装element-plus:yarn add ...

  2. Ngrinder 制作脚本-(二)

    接上一篇文章:了解了Ngrinder的介绍和工作原理之后,相信大家都想着怎么使用这款工具进行性能测试 一.Ngrinder-Controller 的安装 环境要求: (1)jdk1.8以上 (2)Ja ...

  3. vite vue插件打包配置

    import { defineConfig, UserConfigExport, ConfigEnv } from "vite"; import externalGlobals f ...

  4. Kubernetes基础配置管理

    一.ConfigMap创建 1-1.基于目录创建ConfigMap 首先创建一个configmap/conf存储目录,分别建立.conf文件 mkdir /configmap/conf #创建.con ...

  5. 洛谷P4342 [IOI1998]Polygon

    题目 https://www.luogu.com.cn/problem/P4342 我会做IOI题辣 思路 算法设计与分析的课堂例题. 首先这是一个环状DP,那么根据老套路,破环成链.发现要求的东西也 ...

  6. k8s资源清单

    资源清单就是k8s当中用来定义pod的文件,语法格式遵循yaml语法,在yaml当中可以定义控制器类型,元数据,容器端口号等等等....,也可以针对于清单对pod进行删除等操作. 我们可以用kubec ...

  7. 统计学习导论之R语言应用(二):R语言基础

    统计学习导论(ISLR) 参考资料 The Elements of Statistical Learning An Introduction to Statistical Learning 统计学习导 ...

  8. CSP2022 J2参考解析

    目录 P8813 [CSP-J2022] 乘方 P8814 [CSP-J2022] 解密 P8815 [CSP-J2022] 逻辑表达式 P8816 [CSP-J2022] 上升点列 题目传送: P8 ...

  9. connect ETIMEDOUT at PoolConnection.Connection._handleConnectTimeout

    运行 node .\app.js时报错,显示数据库连接超时 此时再运行一次node .\app.js即可

  10. android隐藏apk方式以及apk之间的启动方式

    一.隐藏apk的方式: 在每个项目(apk)中都有一个启动应用的Activity,他的标签是这个: <intent-filter> <action android:name=&quo ...