1 // import provinceData from '../data/city-data/province.js'; 2 // import cityData from '../data/city-data/city.js'; 3 // import areaData from '../data/city-data/area.js'; 4 import { 5 regionData 6 } from 'element-china-area-data' 7 console.log(regionData) 8 let provinceData = [] 9 let cityData = [] 10 let areaData = [] 11 12 function getData(dataList) { 13 let arr = []; 14 (dataList || []).forEach(item => { 15 const { 16 label, 17 value 18 } = item 19 arr = [...arr, { 20 label, 21 value 22 }] 23 }) 24 return arr 25 }; 26 provinceData = getData(regionData); 27 (regionData || []).forEach((item, index) => { 28 cityData = [...cityData, getData(item.children)]; 29 areaData.push([]); 30 (item.children || []).forEach(child => { 31 areaData[index].push(getData(child.children || [])); 32 }) 33 }); 34 console.log(provinceData) 35 console.log(cityData) 36 console.log(areaData)
以上部分为修改内容,其它代码无需变动。