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

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

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react componentDidMount时机问题
    52
    0

    componentDidMount是组件确实渲染成了dom后触发,如果我在这时候append一个绝对定位top0的有颜色的div,预期效果应该是先显示react组件,后立马显示红色div但是实际是直接显示红色div了,都没有闪一下的效果,这是为何?

    class App extends Component {
      constructor(){
        super();
      }
      componentDidMount() {
        const div=document.createElement('div');
        div.style='position:absolute;height:100px;width:100vw;background:blue;top:0';
        document.body.appendChild(div)
      }
      render(){  
        return (
          <div style={{background:'red'}}>hello world</div>
        )
      }
    }
    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部