账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    ReactJS的loading界面不能正常显示
    37
    0

    先贴一下我的代码

    class App extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                data:"",
                loading:true
            };
        }
    
        componentDidMount() {
            //ajax请求数据
            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中执行ajax请求数据期间显示loading界面,在请求数据成功(或者是失败)以后,显示Mainpanel界面信息。但是当我进行调试的时候,直接就进入到Mainpanel,没有显示loading界面。

    PS:loading界面的代码没有问题(我注释掉this.setState({loading:false});以后会一直处于loading界面)

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ◇E控ミ 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部