Vue (28) El-cascader dynamic Loading-provincial and regional components

Source: Internet
Author: User

1. Background interface for click to load the next level, the provincial and regional ID

<template> <el-Cascader v-model= "Selectedoptions"placeholder= "Please select the city and province area": Options= "Cascaderdata"@active-item-change= "Handleitemchange":p Rops="{value: ' ID ', Label: ' Name ', Children: ' Cities '}"></el-cascader></template><script>Exportdefault{name:' My-provinces ', data () {return{departmentoptions: [], Cascaderdata: [], Selectedoptions: []}, methods: {Getnodes (val) {Let Idarea let Sizeareaif(!val) {Idarea=NULLSizearea= 0      } Else if(Val.length = = 1) {Idarea= Val[0] Sizearea= Val.length//3: Level 4: Level Two 6: Level three}Else if(Val.length = = 2) {Idarea= Val[1] Sizearea= Val.length//3: Level 4: Level Two 6: Level three      }       This. $post (' Ibest/service/system/area/arealist ', {        ' ID ': Idarea}). Then (response= {        if(response.data && Response.data.code = = = ' 00000000 ') {Let Items=Response.data.dataif(Sizearea = = 0) {//Initialize load first level province             This. Cascaderdata = Items.map ((value, i) = = {              return{id:value.id, name:value.name, cities: []}} )          } Else if(Sizearea = = 1) {//Click on level two to load the city             This. Cascaderdata.map ((value, i) = = {              if(Value.id = = = Val[0]) {                if(!value.cities.length) {value.cities= Items.map ((value, i) = = {                    return{id:value.id, name:value.name, cities: [] }                  })                }              }            })          } Else if(Sizearea = = 2) {//Click Level two to load level three zone             This. Cascaderdata.map ((value, i) = = {              if(Value.id = = = Val[0]) {Value.cities.map (value, i)= {                  if(Value.id = = = Val[1]) {                    if(!value.cities.length) {value.cities= Items.map ((value, i) = = {                        return{id:value.id, name:value.name} })                    }                  }                })              }            })          }        } Else{console.log (response.data.msg)}}, Error={console.log (Error)})}, Handleitemchange (val) { This. Getnodes (val)}}, mounted () { This. Getnodes ()}}</script>

2. Effects

Vue (28) El-cascader dynamic Loading-provincial and regional components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.