zoukankan      html  css  js  c++  java
  • 地址级联选择器(element-china-area-data插件)

    1.安装

    npm install element-china-area-data -S

    2.引入

    import {regionData, CodeToText, TextToCode} from 'element-china-area-data';

    3.使用

    <el-cascader :options="areaSelectData" :change-on-select="true" :clearable="true" :filterable="true"
    @change="handleChange" class="full-width" size="medium" v-model="form.selectedOptions" />


    data() {
      areaSelectData: regionData, // options绑定的数据就是引入的 regionData
    }

    // 选择公司所在省、市、区
    handleChange() {
    // form.selectedOptions是地址数组,分别对应省市区,下面的操作是将数组转变为字符串保存,如果不需要以字符串形式保存,可以忽略
    this.form.province = this.form.selectedOptions[0];
    this.form.city = this.form.selectedOptions[1];
    this.form.area = this.form.selectedOptions[2];
    if (this.form.province !== undefined) {
    this.buildSurveyData.damRegisterOne.constructionPlace = CodeToText[this.form.province] + ' ';
    }
    if (this.form.city !== undefined) {
    this.buildSurveyData.damRegisterOne.constructionPlace += CodeToText[this.form.city] + ' ';
    }
    if (this.form.area !== undefined) {
    // 拼接公司详细地址
    this.buildSurveyData.damRegisterOne.constructionPlace += CodeToText[this.form.area] + ' ';
    }


    // 由于上面将地址转为了字符串,所以在加载页面获取数据时,要重新将字符串转为数组。下面是对数据的处理
    if(this.buildSurveyData.damRegisterOne.constructionPlace) {
    let address = this.buildSurveyData.damRegisterOne.constructionPlace.split(' ');
    // 省份
    this.form.selectedOptions.push(TextToCode[address[0]].code);
    // 城市
    let cityCode = TextToCode[address[0]][address[1]].code;
    this.form.selectedOptions.push(cityCode);
    // 地区
    let areaCode = TextToCode[address[0]][address[1]][address[2]].code;
    this.form.selectedOptions.push(areaCode);
    }


  • 相关阅读:
    实现activity跳转动画的若干种方式
    Go语言下载网络图片或文件
    安卓获取输入法高度与ViewTreeObserver讲解
    记录某项目中的踩坑与解决(持续更新)
    Flutter安装教程
    安卓多个RecyclerView滑动与显示问题
    java.lang.IllegalStateException: FragmentManager is already executing transactions 及 SmartTabLayout复用
    Java实现中文词频统计
    知乎视频下载(爬虫)
    SuperSpider(简书爬虫JAVA版)
  • 原文地址:https://www.cnblogs.com/xinci/p/10271686.html
Copyright © 2011-2022 走看看