(精華2020年5月22日更新) react基礎篇 元件的使用

2b勿擾發表於2020-05-22
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>簡單元件</title>
</head>

<body>
    <div id="app">

    </div>
    <div id="app1">

    </div>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
        // 簡單的元件
        function Simple(props){
            console.log(props);
            
            return (
                <h2>我是簡單的元件</h2>
            )
        }
        ReactDOM.render(<Simple name="張三"/>,document.getElementById("app"))
        // 複雜的元件 es6 class
        class Complex extends React.Component{
            constructor(){
                super()
            }
            render(){
                return (
                    <div>
                        <h1>我是複雜的元件</h1>
                        <h1>我是複雜的元件</h1>
                    </div>
                )
            }
        }
        ReactDOM.render(<Complex />,document.getElementById("app1"))
    </script>
</body>

</html>

相關文章