在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ ReactJS的loading界面不能正常顯示

ReactJS的loading界面不能正常顯示

先貼一下我的代碼

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data:"",
            loading:true
        };
    }

    componentDidMount() {
        //ajax請(qǐng)求數(shù)據(jù)
        this.setState({loading:false});
    }

        render()
        {
            const loadingstyle = {
                textAlign: 'center',
                lineHeight:'60px',
                marginTop:'95px'
            };
            if(this.state.loading)
            {
                return(
                    <div style={loadingstyle}>
                         //Loading code
                    </div>
                )
            }
            else {
                return (
                    <MainPanel data={this.state.data} />
                )
            }
        }

}

我的想法是在componentDidMount中執(zhí)行ajax請(qǐng)求數(shù)據(jù)期間顯示loading界面,在請(qǐng)求數(shù)據(jù)成功(或者是失?。┮院?,顯示Mainpanel界面信息。但是當(dāng)我進(jìn)行調(diào)試的時(shí)候,直接就進(jìn)入到Mainpanel,沒(méi)有顯示loading界面。

PS:loading界面的代碼沒(méi)有問(wèn)題(我注釋掉this.setState({loading:false});以后會(huì)一直處于loading界面)

回答
編輯回答
醉淸風(fēng)

你在ajax里面,請(qǐng)求成功后調(diào)this.setState({ loading:false })

2018年9月22日 22:55