【问题标题】:Target container is not a DOM element in ReactJS目标容器不是 ReactJS 中的 DOM 元素
【发布时间】:2018-10-17 12:43:31
【问题描述】:

我刚开始学习ReactJS,并且成功编写了我的第一个代码。当相同的模式出现在组件上时,我收到一个错误提示 _Invariant Violation: registerComponent(...): Target container is not a DOM element. 在控制台中.我正在使用 react 和 babel cdn 而不是下载和导入。

<div id="=f_compo"></div>
<script type="text/babel">
    var compo= React.createClass({
        render: function(){
            return (<h3>This is a simple component</h3>);
        }
    });
    ReactDOM.render(<compo/> ,document.getElementById('f_compo'));
</script>

这是我的 index.html 代码(由于发布问题时出现错误,我删除了 head 标签中的 cdn 链接)并且 以下内容 是错误我收到了。

错误:

_不变式 _registerComponent _renderNewRootComponent 包装 renderSubtreeIntoContainer 使成为 包装 一世 r ○ 你 F

由于谷歌的解决方案很少,我需要一个明确的解释,提及为什么会出现这种错误?如何以正式的方式解决? p>

【问题讨论】:

    标签: javascript jquery html reactjs babeljs


    【解决方案1】:

    打错字了

    // You declared id as "=f_compo"
    <div id="=f_compo"></div>
    <script type="text/babel">
        var compo= React.createClass({
            render: function(){
                return (<h3>This is a simple component</h3>);
            }
        });
        //Find the same ID here. Right now it's "=f_compo" not "f_compo"
        ReactDOM.render(<compo/> ,document.getElementById('f_compo'));
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多