diff --git a/src/pages/CityList/index.js b/src/pages/CityList/index.js index c7d1a3a..6e019a6 100644 --- a/src/pages/CityList/index.js +++ b/src/pages/CityList/index.js @@ -71,14 +71,20 @@ const back = () => { } // ); // } export default class CityList extends React.Component { - state = { - cityList: {}, - cityIndex: [], - activeIndex: 0 + + constructor(props){ + super(props) + this.state = { + cityList: {}, + cityIndex: [], + activeIndex: 0 + } + const cityListComponent = React.createRef() } - componentDidMount() { - this.getCityList() - console.info("componentDidMount") + async componentDidMount() { + await this.getCityList() + //提前计算list高度 + this.cityListComponent.current.measureAllRows() } async getCityList() { const res = await axios.get('http://localhost:8080/area/city?level=1') @@ -134,11 +140,19 @@ export default class CityList extends React.Component { renderCityIndex() { const { cityIndex, activeIndex } = this.state return cityIndex.map((item, index) => { -