element-china-area-data - npm element-china-area-data文字、编码转换_fdksfskldfdslkfs的博客-CSDN博客 vue 城市选择器(省市区)的使用 element-china-area-data_Simplicity438的博客-CSDN博客_vue地区选择器 组件学习: 组件 | Element 工具类里代码: import { CodeToText, TextToCode } from 'element-china-area-data' // 地区码与中文字符串互相转换 export function convertCodeAndText(codeArray) { if (typeof (codeArray) === 'string') { let arr = [] arr = codeArray.split(' ') let c = {} const data = [] for (let i = 0; i <= arr.length - 1; i++) { if (i === 0) { c = TextToCode[arr[i]] data.push(c.code) } else { c = c[arr[i]] data.push(c.code) } } return data } else { if (codeArray === null) { return '' } let area = '' switch (codeArray.length) { case 1: area += CodeToText[codeArray[0]] break case 2: area += CodeToText[codeArray[0]] + ' ' + CodeToText[codeArray[1]] break case 3: area += CodeToText[codeArray[0]] + ' ' + CodeToText[codeArray[1]] + ' ' + CodeToText[codeArray[2]] break default: break } return area } }