• react实例8-组件,参数更新


    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>test01</title>
    <script src="build/browser.min.js"></script>
    <script src="build/react.js"></script>
    <script src="build/react-dom.js"></script>
    <script type="text/babel">
    class ChildComp extends React.Component{
    componentWillReceiveProps(){
    console.log('参数更新啦');
    }
    render(){
    return <span>{this.props.name}</span>
    }
    }

    class ParentComp extends React.Component{
    constructor(...args){
    super(...args);
    this.state={i:0};

    }
    fn(){
    this.setState({
    i:this.state.i+1
    });
    }
    render(){

    return <div>
    <input type="button" value="aaa" onClick={this.fn.bind(this)}/>
    <ChildComp name={this.state.i} />
    </div>
    }
    }

    window.onload=function(){
    ReactDOM.render(
    <ParentComp/>,
    document.getElementById('app'),function(){
    console.log("渲染成功啦")
    }
    );
    }

    </script>
    </head>

    <body>
    <div id="app"></div>


    </body>
    </html>

  • 相关阅读:
    php环境下所有的配置文件以及作用
    获取登陆用户的ip
    curl模拟post和get请求
    linux 下安装php curl扩展
    php常用面试知识点
    git使用步骤
    laravel框架基础知识点
    ci框架基础知识点
    ajax
    Mysql 中需不需要commit
  • 原文地址:https://www.cnblogs.com/codepen2010/p/6853573.html
Copyright © 2020-2023  润新知