React的输出无响应

时间:2016-09-03 23:53:57

标签: reactjs

你好,我是ReactJs的新手。我试图在浏览器中运行此代码,但输出为空白。请帮忙。

<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>react</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.29/browser.js"></script>
</head>
<body>
<script type="text/bable">
    var HelloWorld = React.CreateClass({
        render: function() {
            return <div>
                <h1> Hello World! </h1>
                <p>This is some text</p>
            </div>
        }
    });
    React.render(<HelloWorld />, document.body);
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

<script type="text/bable">
    var HelloWorld = React.createClass({
        render: function() {
            return (
                <div>
                    <h1> Hello World! </h1>
                    <p>This is some text</p>
                </div>
            )
        }
    });

    ReactDOM.render(<HelloWorld />, document.body);

</script>

首先,使用React.createClass 其次,将返回包含在()中,因为您返回了一个DOM元素块 第三,我们现在使用ReactDOM.render()而不是React.render()