vue +iview Select省市区联动
因为需要保存的表里只有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;
}
如果有更优化的方案,烦请留言指导
vue +iview Select省市区联动的更多相关文章
- vue iview Select bug,在低版本浏览器中报错
iview是个好东西,今天第一次试用,用来做了一个app,但是在安卓5.1各种报错啊,头痛的是不知道具体哪行代码错了,总是报错undefined is not a function. 倒腾了半天,原来 ...
- vue+iview多条联动,for循环data是函数
问题:多条for循环出的数据二级联动for循环出多条数据,每条数据都有一个二级联动,每次下拉一级联动,二级的选项都是变化的. 思考刚开始一直想不出如何实现二级联动下拉的数据动态变化,因为之前一直都是v ...
- JS省市区联动
JS省市区使用文档 一:服务器返回JSON格式要求如下网址里面data的格式:(拿KISSY组件data格式来做的) http://gallery.kissyui.com/cityselector/d ...
- JS省市区联动效果
省市区联动下拉效果在WEB中应用非常广泛,尤其在电商网站最为常见.一般使用Ajax实现无刷新下拉联动.利用jQuery,通过读取JSON数据,实现无刷新动态下拉省市二(三)级联动效果. 首先我们可以看 ...
- 基于AngularJs + Bootstrap + AngularStrap 省市区联动实践
什么是 AngularJs?网上一大堆资料,没能真正说明白. AngularJs 就是一个函数库,算不上一个框架,源码2万2千多行,提供了前端MVC的开发方式, 有双向绑定,指令等特性,这是具有革命性 ...
- uniapp自定义简单省市区联动组件
又双叒一个uniapp组件 最近有一个选择地址的需求,就写了一个省市区联动选择器. 选择日期使用的picker,就照着它简单的整了一个,使用网络请求城市数据,还用到了vuex组件数据共享. 本来自己整 ...
- 简单jquery实现select三级联动
简单的jquery实现select三级联动 代码如下: <!DOCTYPE html> <html> <head> <meta charset="u ...
- SharePoint 2010 自定义 字段 类型--------省市区联动
转:http://www.cnblogs.com/sp007/p/3384310.html 最近有几个朋友问到了有关自定义字段类型的问题,为了让更多的人了解自定义字段类型的方法,特写一篇博客与大家分享 ...
- thinkphp5+vue+iview商城 公众号+小程序更新版本
thinkphp5+vue+iview商城加分销 源码下载地址:http://github.crmeb.net/u/crmeb 演示站后台:http://demo25.crmeb.net 账号:dem ...
- vue & iview
vue & iview ui components https://codepen.io/webgeeker/pen/EJmQxQ https://www.iviewui.com/docs/g ...
随机推荐
- conda pytorch 配置
主要步骤: 0.安装anaconda3(基本没问题) 1.配置清华的源(基本没问题) 2.查看python版本,运行 python3 -V: 查看CUDA版本,运行 nvcc -V 3.如果想用最新版 ...
- linux 服务器 重命名
vim /etc/hosts 追加 10.10.134.68 RmcbTestDB3 RmcbTestDB3 # ip 名称 名称 127.0.0.1 localhost ...
- mac怎么设置开机自启动项,mac选择开机启动项
转自 https://www.zhangshilong.cn/work/386853.html Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/L ...
- fastapi loguru
使用loguru记录日志 安装 pip install loguru 基本使用 那么这个库怎么来用呢?我们先用一个实例感受下: In [1]: from loguru import logger .. ...
- springboot+mybais配置多数据源(分包实现)
一.分包方式实现: 1.在application.properties中配置两个数据库: #druid连接池 #dataSoureOne(这里是我本地的数据源) spring.datasource.o ...
- mariadb数据库用户管理(创建、赋权、)
数据库查看当前用户 select user(): MariaDB [(none)]> select user(); +----------------+ | user() | +-------- ...
- unity创建一个数组,让他随机生成一个东西之C#语言(有图教程)
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...
- echart 悬浮窗超边界了怎么办?
悬浮窗超边界了怎么办? 在渲染界面函数里面 写一个 // tooltip浮窗未知 chartOption.tooltip.position = function(point, params, dom, ...
- 其他2-while+read按行读取文件
一.三种方法 1.exec读取文件 exec <file sum=0 while read line do cmd done 2. cat读取文件 cat file|while read lin ...
- 阿里云 rocketMq 延时消息
初始化消费者和生产者 生产者 设置rocketmq的accesskey 和secretkey 以及rocketmq的 binder server. 首先 编辑一个配置类,将关于配置rocketmq的东 ...