其他分享
首页 > 其他分享> > Vue+elementUI省市区三级联动的实现

Vue+elementUI省市区三级联动的实现

作者:互联网

安装依赖element-china-area-data

npm install element-china-area-data -S

引入数据

import { 
    provinceAndCityData, 
    regionData,
    provinceAndCityDataPlus, 
    regionDataPlus, 
    CodeToText, 
    TextToCode 
} from 'element-china-area-data'

使用

<template>
  <div id="app">
    <el-cascader
      size="large"
      :options="options"
      v-model="selectedOptions"
      @change="handleChange">
    </el-cascader>
  </div>
</template>
 
<script>
  import { 
    provinceAndCityData, 
    regionData,
    provinceAndCityDataPlus, 
    regionDataPlus, 
    CodeToText, 
    TextToCode 
  } from 'element-china-area-data'

  export default {
    data () {
      return {
        options: regionData,
        selectedOptions: []
      }
    },
 
    methods: {
      handleChange (value) {
         console.log('编码',value);
	     console.log('省:', CodeToText[value[0]]);
         console.log('市:', CodeToText[value[1]]);
         console.log('区:', CodeToText[value[2]]);
      }
    }
  }
</script>

 

标签:Vue,elementUI,CodeToText,value,TextToCode,regionData,省市区,data
来源: https://blog.csdn.net/fengyiyangdeli/article/details/121990148