Reactdom不会呈现简单的文本

时间:2017-11-01 09:09:36

标签: reactjs

我试图渲染一个简单的文字,但它什么也没渲染。我已经安装了react,reactdom,webpack和bable。任何关于它为什么不起作用的想法?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React and Spring Boot</title>
</head>
<body>
    <div id='root'></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
    <script type="text/babel">
        import React from 'react';
        import ReactDOM from 'react-dom';
        ReactDOM.render(
                <h1>Test</h1>, document.getElementById('root')
        );
    </script>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

 It works...its just that import is not understood by the browser

    
    ReactDOM.render(
            <h1>Test</h1>, document.getElementById('root')
    );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react-dom.js"></script>
 
 <div id="root"></div>

答案 1 :(得分:0)

删除import语句对我有用。请检查工作代码段。

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React and Spring Boot</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
</head>
<body>
    <div id='root'></div>
    <script type="text/babel">
        ReactDOM.render(
                <h1>Test</h1>, document.getElementById('root')
        );
    </script>
</body>
</html>
&#13;
&#13;
&#13;