zoukankan      html  css  js  c++  java
  • React 多组件传值props和this

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
    <script src="js/browser.min.js"></script>
    </head>
    <body>
    <div id="example"></div>

    <script type="text/babel">
    var AComponent = React.createClass({
    handleChange:function(){
    console.log(this.refs.inputTxt.value);
    this.props.funcSave(this.refs.inputTxt.value);
    },
    render:function(){
    return <input
    ref='inputTxt'
    onChange={this.handleChafuncSavenge}
    type='text'/>;
    }
    })

    var BComponent = React.createClass({
    handleClick:function(){
    console.log(this.props.funcGet());
    },
    render:function(){
    return <button onClick={this.handleClick}>
    {this.props.name}
    </button>;
    }
    })

    var MainComponent = React.createClass({
    result:0,
    save:function(value){
    console.log("in mainComponent value is "+value);
    this.result = value;
    },
    get:function(){
    return this.result;
    },
    render:function(){
    return <div>
    <AComponent funcSave={this.save}/>
    <BComponent funcGet={this.get} name='获取输入的值'/>
    </div>
    }
    })

    ReactDOM.render(
    <MainComponent/>,
    document.getElementById('example')
    )

    </script>

    </body>
    </html>
  • 相关阅读:
    踏实每一个脚印——2019年12月复盘
    修改博客园markdown编辑器代码高亮风格的方法
    Hyperion: Building the Largest In memory Search Tree
    C++11——智能指针
    拷贝控制
    分布式系统常见概念
    extern和static使用
    APUE—UNIX文件系统
    C++的一些细节
    fork和僵尸进程
  • 原文地址:https://www.cnblogs.com/dianzan/p/7323525.html
Copyright © 2011-2022 走看看