vant框架 area 组件使用,省市区联动数据生成

组件使用

<van-area title="标题" swipe-duration="200" :area-list="reachList" @confirm="cityConfirmFn"/>

原数据格式

reachList : { province_list: {}, city_list: {}, county_list: {}, }

数据生成

  • 地区码为 6 位数字,前两位代表省份,中间两位代表城市,后两位代表区县,以 0 补足 6 位。
  • 省:110000
let tempObj = {}
provinceData.map((d,index)=>{ tempObj[this.notWorthAddFn('1'+(index+1))] = d.Name }) 
this.reachList.province_list = tempObj
  • 市:001100
let tempObj = {}
cityData.map((d,index)=>{  tempObj[this.notWorthAddFn('1'+this.pIndex+(index<9? '0'+(index+1):(index+1)))] = d.Name }) 
this.reachList.city_list= tempObj
  • 区:000011
let tempObj = {}
countyData.map((d,index)=>{ tempObj[this.notWorthAddFn('1'+this.pIndex+(this.cIndex<10?'0'+this.cIndex:this.cIndex)+(index<9? '0'+(index+1):(index+1)))] = d.Name }) 
this.reachList.county_list= tempObj
  • 补充不足留位
notWorthAddFn(t){
    let v = 6-t.length
    if(t.length < 6){
        for(let o=0;o<v;o++){t = t+'0'}
    }
    return t
},
  • 点击确定的事件处理, o 为组件实例
cityConfirmFn(o){
    this.purseOpt.r_prov = o[0].name
    this.purseOpt.r_city = o[1].name
    this.purseOpt.r_area = o[2].name
    let cityStr = ''
    o.map((d,di)=>{
        cityStr = cityStr+(di=='0'?'':'-')+d.name
    });

    this.reachCity = cityStr;
    this.reachCitySelSta = false
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值