zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    RabbitMQ详解(一)——安装
    智能风控平台核心之风控决策引擎(一)
    Redis6详解(一)——概述与安装
    SpringMVC(一)——入门案例
    数据结构与算法(一)——概述
    JDK1.8源码(二)——java.lang.Integer类
    设计模式(一)——概述
    Java基础(五)——String
    first 博客园
    Django
  • 原文地址:https://www.cnblogs.com/xsj1989/p/15250962.html
Copyright © 2011-2022 走看看