码迷,mamicode.com
首页 > 其他好文 > 详细

使用vant的地域控件追加全部选项

时间:2019-07-19 21:13:16      阅读:559      评论:0      收藏:0      [点我收藏+]

标签:vue   position   tom   picker   tco   sel   cli   mil   set   

记录是为了更好的成长!

 

在项目中使用了vant的Area插件,需要进行全部匹配,vant本身没有实现,需要改造代码,方法如下:

<div class="site">
    <span class>起点</span>
    <van-cell v-model="start" @click="areaSelect(0)"></van-cell>
</div>
<div class="site">
    <span>终点</span>
    <van-cell v-model="end" @click="areaSelect(1)"></van-cell>
</div>
<van-popup v-model="show" position="bottom">
    <van-area :area-list="areaList" @cancel="onCancel" @confirm="onConfirm" @change="change" ref="area" />
</van-popup>

 

vue的methos中添加下面两个方法:

change(picker, value, index){
      if(value[0].code != 100000){

        if(index == 0){
          let addr = this.areaList;
          let areaListCode = value[0].code;
          let code1 = Object.assign({},addr.city_list,{[areaListCode]:"全部"});
          let code2 = Object.assign({},addr.county_list,{[areaListCode]:"全部"});
          this.areaList.city_list = code1;
          this.areaList.county_list = code2;
        }
        if (index == 1) {
          let addr = this.areaList;
          let areaListCode = value[1].code;
          let code = Object.assign({},addr.county_list,{[areaListCode]: "全部"});
          this.areaList.county_list = code;
        }
      }
    },
    areaSelect(type) {
      let addr = this.areaList;
      this.PickerType = type;
      this.show = true;     
      if(this.PickerType == 1 && this.endAddrInfo == "请选择"){
          this.$refs.area.reset();
      };
      let province_list = Object.assign({},addr.province_list,{100000:"全部"});
      let city_list = Object.assign({},addr.city_list,{100100:"全部"});
      let county_list = Object.assign({},addr.county_list ,{100101:"全部"});
      this.areaList={
        province_list,city_list,county_list
      };
    },

 

 

以上内容代表个人观点,仅供参考,不喜勿喷。。。

使用vant的地域控件追加全部选项

标签:vue   position   tom   picker   tco   sel   cli   mil   set   

原文地址:https://www.cnblogs.com/newbest/p/11215390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!