vue+ElementPlus实现中国省市区三级级联动封装

安装插件获取中国省份的所有数据

javascript 复制代码
 npm install element-china-area-data -S

借助ElementPlus 级联选择器 Cascader实现

javascript 复制代码
<template>
    <div>
     <el-cascader
          size="large"
          :options="options"
          v-model="selectedOptions"
          @change="handleChange">
        </el-cascader>
        {{  selectedOptions  }}

    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { regionData ,codeToText } from 'element-china-area-data'
const options = ref(regionData)  //数据
const selectedOptions = ref([]) //选中的数据
//当选中值变化时触发的事件
const handleChange=(value:any) =>{
    console.log(value) //区域码
     if (
        selectedOptions.value[0] != null &&
        selectedOptions.value[1] != null &&
        selectedOptions.value[2] != null
    ) {
        const str =
            codeToText[selectedOptions.value[0]] +
            '/' +
            codeToText[selectedOptions.value[1]] +
            '/' +
            codeToText[selectedOptions.value[2]]
        console.log(str)  //中文
    }
}

</script>

<style lang="scss" scoped>

</style>
实现效果
相关推荐
明远湖之鱼7 分钟前
浅入理解跨端渲染:从零实现 React DSL 跨端渲染机制
前端·react native·react.js
悟忧42 分钟前
规避ProseMirror React渲染差异带来的BUG
前端
小皮虾1 小时前
小程序云开发有类似 uniCloud 云对象的方案吗?有的兄弟,有的!
前端·javascript·小程序·云开发
QuantumLeap丶1 小时前
《uni-app跨平台开发完全指南》- 05 - 基础组件使用
vue.js·微信小程序·uni-app
Android疑难杂症1 小时前
鸿蒙Notification Kit通知服务开发快速指南
android·前端·harmonyos
T___T1 小时前
全方位解释 JavaScript 执行机制(从底层到实战)
前端·面试
阳懿1 小时前
meta-llama-3-8B下载失败解决。
前端·javascript·html
Qinana1 小时前
🌊 深入理解 CSS:从选择器到层叠的艺术
前端·css·程序员
IT_陈寒1 小时前
Python 3.12新特性实测:10个让你的代码提速30%的隐藏技巧 🚀
前端·人工智能·后端
史林枫1 小时前
JavaScript 中call和apply的详细讲解 —— 连10岁的小朋友都能看懂!
javascript·apply·call