因为需要保存的表里只有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. centos6.x配置虚拟主机名及域名hosts

    我们在本地安装了centos或者虚拟主机上安装了centos,主机名称默认是localhost,这样我们可以使用localhost访问我们的主机,在终端命令里默认的是[root@localhost ~ ...

  2. apk反编译工具--dex2jar

    dex2jar 2.1 https://github.com/pxb1988/dex2jar/releases 链接: https://pan.baidu.com/s/1ZU16mPE_QNhzWxF ...

  3. 统计学习导论之R语言应用(三):线性回归R语言代码实战

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

  4. JS学习-async/await

    async/await 它保证函数的返回值为 promise. 用更少的.then()块来封装代码,同时它看起来很像同步代码 注意:可能会因为大量await的promises相继发生而变慢. asyn ...

  5. iOS底层原理02-alloc源码分析

    首先,从最熟悉的入手 - 对象,看看这三个对象的内容,内存地址和指针地址. LGPerson *p1 = [LGPerson alloc];    LGPerson *p2 = [p1 init];  ...

  6. spring boot读取本地文件

    File file = ResourceUtils.getFile("classpath:face/1112.txt"); InputStream inputStream = ne ...

  7. 动画图解 Git 的 10 大命令

    原文地址:https://dev.to/lydiahallie/cs-visualized-useful-git-commands-37p1 原文作者:Lydia Hallie 前言 尽管 Git 是 ...

  8. linux(centos7)下部署jenkins

    1.安装jdk yum install -y java 确保已经安装了jdk,查看是否安装jdk命令参考地址: 2.安装jenkins 2.0添加Jenkins库到yum库,Jenkins将从这里下载 ...

  9. Monkey 用户指南(译)

    原址:https://developer.android.com/studio/test/monkey.html 帮助:google翻译:https://translate.google.cn/ 自己 ...

  10. elementUI el-tree报错 Cannot read property ‘setCheckedKeys’ of undefined"

    给树节点赋值时,执行下面代码会报错,原因是:DOM元素未加载完成. 以下为错误写法. handleRowClick(row) { this.$refs.tree.setCheckedKeys(ids) ...