react 메시지 기능 준비1

5264 단어 react

 1. props 
 2.  , render , 



<html lang="zh-cn">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>title>
        <script src="./src/react.js">script>
        <script src="./src/react-dom.js">script>
        <script src="./src/browser.min.js">script>
    head>

    <body>
        <div id="demo">div>
        <script type="text/babel">

            var FirstComponent = React.createClass({
                getInitialState:function () {
                    return {
                        mes:this.props.value
                    }
                },
                    render:function (){
                        return (
                            <div>
                                <h1>{this.props.title}h1>

                                {/*value this.props value , , state ;onchange */}
                                <input type="text" value={this.state.mes} onChange={this.changeHandle}/>

                                <input type="button" value={this.props.sendName} />

                                {/* */}
                                <p>{this.state.mes}p>
                            div>
                        )   
                    },
                changeHandle:function (ev) {
                        console.log(ev.target.value)
                    this.setState({mes:ev.target.value})

                }
                });



            var obj = {
                title:' react ',
                sendName:' ',
                value:" "
            }

            ReactDOM.render(
                <FirstComponent {...obj} />,
                document.getElementById("demo"),
                function(){
                    console.log(" ");
                }
            );

        script>
    body>
html>

좋은 웹페이지 즐겨찾기