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


    记录是为了更好的成长!

    在项目中使用了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
          };
        },

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

  • 相关阅读:
    作为一个程序猿,是不是经常会用到.chm文档,但是我们可能会遇到这样那样的问题,比如.chm文档打不开
    总结
    图片轮播的几种方式
    学习中于遇到的问题总结
    node 总结
    webpack 总结
    babel 的总结和理解
    关于css 的AST 语法树的理解
    js中的正则表达式
    八皇后
  • 原文地址:https://www.cnblogs.com/newbest/p/11215390.html
Copyright © 2020-2023  润新知