加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 检查是否已安装所有子组件

发布时间:2020-12-15 20:47:30 所属栏目:百科 来源:网络整理
导读:有没有办法检测孩子是否已经安装?初始化同位素时,必须安装所有子组件以进行初始化.超时为5ms,它的工作方式与预期相符,但我确信有更好的方法. componentDidMount: function() { var container = this.refs.vinesOverview.getDOMNode(); setTimeout(function(
有没有办法检测孩子是否已经安装?初始化同位素时,必须安装所有子组件以进行初始化.超时为5ms,它的工作方式与预期相符,但我确信有更好的方法.
componentDidMount: function() {
    var container = this.refs.vinesOverview.getDOMNode();

    setTimeout(function() {
      var isotope = new Isotope(container,{
        itemSelector: ".vine_item",layoutMode: "masonry",resizable: true,gutter: 0,isFitWidth: true
      });

      this.setState({ isotope: isotope });
    }.bind(this),5);
}

UPDATE

我现在试过这个:

componentDidMount: function() {
    var container = this.refs.vinesOverview.getDOMNode();
    console.log(container.offsetHeight); // console output 0
    setTimeout(function() {
        console.log(container.offsetHeight); // console output 3150
    },5);
  },

那么在5ms后它计算出了高度?这就是同位素不起作用的原因.这是一个Bug还是正常的?谢谢!

在父项上调用componentDidMount之前,React等待挂载所有子组件.如果你发现一个不成立的情况,请提交一个错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读