antd vue 多个下拉 联动_Vue中h5三个下拉框实现省级联动

  • Post author:
  • Post category:vue


请选择您所在的区域

v-for=”item in provincOptions”:key=”item.id”:label=”item.area_name”:value=”item.id”>

v-for=”item in cityOptions”:key=”item.id”:label=”item.area_name”:value=”item.id”>

v-for=”item in countyOptions”:key=”item.id”:label=”item.area_name”:value=”item.id”>

下一步

getCity,

queryArea,

editArea

}from “../industry”; //引入接口(注意文件路径)

export default{

data() {return{

isDisabledSubmitBtn:false,

province_id:”,

province_name:”,

city_id:”,

city_name:”,

county_id:”,

county_name:”,

provincOptions:[],

cityOptions:[],

countyOptions:[],

selectArea:null};

},

created() {this.getArea()

},

methods: {//获取省市区(数据回显)

getArea() {

letparams={

unionid:this.unionid

}

queryArea(params).then(res =>{this.selectArea =res.data;this.getProvinceList(0)this.province_id = this.selectArea.provinceIdthis.province_name = this.selectArea.provinceNamethis.getCityList(this.province_id)this.city_id=this.selectArea.cityIdthis.city_name=this.selectArea.cityNamethis.getCountyList(this.city_id)this.county_id=this.selectArea.countyIdthis.county_name=this.selectArea.countyName

})

},//提交前的数据校验

valid() {

let that=this

if (!that.province_id) {

that.$toast({

message:’请选择省’,

duration:2000});return false;

}if (!that.city_id) {

that.$toast({

message:’请选择市’,

duration:2000});return false;

}if (!that.county_id && this.countyOptions.length >= 1) {

that.$toast({

message:’请选择区’,

duration:2000});return false;

}return true;

},//获取省列表

getProvinceList() {

letparams={

parentId:0}

getCity(params).then(res =>{this.provincOptions =res.data

})

},//获取市列表

getCityList(province_id) {this.city_id=”

this.city_name=”

this.county_id=”

this.county_name=”

this.countyOptions=[]

letparams={

parentId:this.province_id

}if (this.province_id) {

getCity(params).then(res =>{this.cityOptions =res.data

})

}else{this.cityOptions =[] //每一次选择新的省之后清空,防止错乱

}

},//获取区列表

getCountyList(city_id) {

letparams={

parentId:this.city_id

}this.county_id = ”    this.county_name=”

if (this.city_id) {

getCity(params).then(res =>{this.countyOptions =res.data

})

}else{this.countyOptions =[] //每一次选择新的省之后清空,防止错乱

}

},//提交数据

submitArea(){if(this.valid()){this.isDisabledSubmitBtn=true //按钮置灰,防止用户不断点击//循环得到省市区名字

for(var i = 0;i

}

}for(var i = 0;i

}

}for(var i = 0;i

}

}

letparams={

provinceId:this.province_id,

provinceName:this.province_name,

cityId:this.city_id,

cityName:this.city_name,

countyId:this.county_id,

countyName:this.county_name //传入后台所需要的参数

}

editArea(params).then(res=>{if(res.code==1){//提交成功后的操作

}else{this.isDisabledSubmitBtn=false //按钮恢复高亮

this.$toast({

message: res.message,

duration:2000});

}

})

}

}

}

};

opacity:1 !important;

}



版权声明:本文为weixin_28993425原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。