在使用的react版本如下:
import React from 'react'
import { IndexBar, List } from 'antd-mobile';
import axios from 'axios';
import NavHeader from '../../components/NavHeader';
import { getCurrentCity } from '../../utils'
import './style.css';
const charCodeOfA = 'A'.charCodeAt(0);
let groups = Array(26)
.fill('')
.map((_, i) => ({
title: String.fromCharCode(charCodeOfA + i),
items: []
}))
// 获取热门城市数据
// let cityHot = []
// const hotRes = axios.get('http://localhost:8080/area/hot').then(hotRes=>{
// cityHot = hotRes.data.body
// List['hot'] = hotRes.data.body
// List.unshift('hot')
// })
// // 获取当前定位城市
// const curCity = getCurrentCity()
// List['#'] = [curCity]
// List.unshift('#')
let cityList = []
const res = axios.get('http://localhost:8080/area/city?level=1').then(res=>{
cityList = res.data.body
groups.map((item)=>{
cityList.map((city)=>{
if(city.pinyin.slice(0,1).toUpperCase()==item.title){
item.items.push(city)}
})
})
})
export default () => {
return (
<div className='citylist'>
{/* 顶部导航栏 */}
<NavHeader>城市选择</NavHeader>
{/* IndexBar序列 */}
<div className='indexbar' style={{ height: window.innerHeight - 45 }}>
<IndexBar>
{groups.map(group => {
const { title, items } = group;
return (<IndexBar.Panel index={title} title={`${title}`} key={`${title}`}>
<List>
{items.map((item, index) => (<List.Item key={index}>{item.label}</List.Item>))}
</List>
</IndexBar.Panel>);
})}
</IndexBar>
</div>
</div>
)
}
目前效果:
请问代码应该如何修改?