• vue.js使用element-ui 和 el-cascader


    安装:npm i element-ui -S
    回显:https://blog.csdn.net/weixin_42125732/article/details/118103756
    import { regionData,CodeToText,TextToCode } from 'element-china-area-data'
    areas-zh-cn.js:https://pan.baidu.com/s/1k4bc68Zm-29YDGHCkYkAmA 提取码:kdaa

    <template>
      <div>
        <h1>TEST</h1>
        <el-cascader
          :options="options"
          v-model="areas"
          :props="optionProps"
          @change="handleChange"
        ></el-cascader>
        <div>省市区:{{ areanames }}</div>
        <button v-on:click="handleAreaNames">TEST</button>
      </div>
    </template>
    <script>
    import areasZhCn from "@/utils/areas-zh-cn.js";
    export default {
      name: "home",
      data() {
        return {
          options: areasZhCn,
          optionProps: { value: "id", label: "name", children: "child" },
          areas: [],
          areanames: undefined,
          lastAreaCode: undefined,
        };
      },
      methods: {
        handleChange(value) {
          if (value.length > 2) {
            this.lastAreaCode = value[2];
          } else if (value.length > 1) {
            this.lastAreaCode = value[1];
          } else {
            this.lastAreaCode = value[0];
          }
        },
        handleAreaNames() {
          let carea = this.lastAreaCode + "";
          let a1 = parseInt(carea.substring(0, 2) + "0000");
          let a2 = parseInt(carea.substring(0, 4) + "00");
          let a3 = parseInt(carea);
    
          // let ars = [a1, a2, a3];
          // this.areas = ars;
    
          let n1 = areasZhCn.filter(function (n) {
            return n.id == a1;
          })[0];
    
          let n2 = undefined;
          if (n1 != undefined && n1.child != undefined) {
            n2 = n1.child.filter(function (n) {
              return n.id == a2;
            })[0];
          }
    
          let n3 = undefined;
          if (n2 != undefined && n2.child != undefined) {
            n3 = n2.child.filter(function (n) {
              return n.id == a3;
            })[0];
          }
          this.areanames =
            (n1 ? n1.name : "") + (n2 ? n2.name : "") + (n3 ? n3.name : "");
        },
      },
      created: function () {},
    };
    </script>
    
  • 相关阅读:
    PHP中有多态么
    【Android】九宫格实现
    采用xshell链路本地虚拟机Linux
    读取资源文件的工具.
    dede织梦背景经常使用标签
    PHP第三个教训 PHP基本数据类型
    Linux经常使用的命令(必看)
    易Android登录Demo
    [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
    web开发性能优化---UI接口章
  • 原文地址:https://www.cnblogs.com/xsj1989/p/15250962.html
Copyright © 2020-2023  润新知