因为需要保存的表里只有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. css代码中的2个类名连一起写是啥意思?

    <div class="menu-btn closed"> <div class="menu-line"></div> &l ...

  2. Apache 基本配置 代理 重定向 跨域 https ssl证书 在windows下常用命令

    官网下载地址 https://httpd.apache.org/ => https://httpd.apache.org/docs/current/platform/windows.html#d ...

  3. java-功能-参数校验

    1.map中数据 if (null == input.get("logId") || StringUtils.isBlank((String) input.get("lo ...

  4. idea提交时忽略.class、.iml文件和文件夹或目录的方法

    第一种方法 在Setings–> Editor --> File Types -->Ignore files and folders中添加需要忽略的文件和文件夹: .idea 忽略 ...

  5. WPF中向下拉框中绑定枚举体

    1.枚举绑定combox的ItemsSourceItemsSource绑定的是个集合值,要想枚举绑定ItemsSource,首先应该想到的是把枚举值变成集合. 方法一:使用资源里的ObjectData ...

  6. 解决The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB

    问题 yang@k8s-master:/etc/apt/sources.list.d$ sudo apt update Get:1 https://mirrors.aliyun.com/kuberne ...

  7. iOS 12.3 - iOS 13.X 爱思助手越狱教程

    原文链接 本教程使用工具为爱思助手 Mac 版,Windows 电脑可以安装"黑苹果"系统后,在"黑苹果"系统内安装爱思助手再进行操作. 支持设备:iPhone ...

  8. windows 系统的端口问题

    netstat -ano 列出所有正在使用的端口netstat -aon|findstr "4300" 查询占用该端口的PIDtasklist|findstr "4464 ...

  9. Python批量修改文件名中所包含指定关键字的文件

    1.去掉下图中各文件名中的'xx' 2.Python代码如下(仅供参考) import os, os.path, time def rename(file, keyword): #file: 需要修改 ...

  10. pg数组类型

    数据库版本 postgres=# SELECT version(); version---------------------------------------------------------- ...