• react组件之间的参数传递


    1、父组件向子组件传递参数

    class Child extends Component {
        componentDidMount(){
          let name = this.props.default;
          console,log(name);
        }
        render(){
          const { default} = this.props;
          return (
            <Input />
          )
    }
    }
    import React, { Component } from 'react';
    import Child from './Child';
    
    class Parent extends Component {
        state = {
            name: 'Bob'
        }
        render() {
            return (
                <div>
                    <Child default={this.state.name} />
                </div>
            )
        }
    }

    2、子组件向父组件传递参数

    class Child extends Component {
        state={
          name:'Bob'
        }     componentDidMount(){
          this.props.toParent(this.state.name);
       }
        render(){       return (         <Input />       ) } }
    import React, { Component } from 'react';
    import Child from './Child';
    
    class Parent extends Component {
       state = {
        name:''
    } getChildInfo = (name)=>{
         this.setState({name:name});
       }
    render() { return ( <div> <Child toParent={this.getChildInfo.bind(this)} /> </div> ) } }
  • 相关阅读:
    Jquery 复习01
    工具和资源
    常用 npm 和 yarn 命令
    Jenkins 安装 ruby-runtime 出错
    shiro+jwt 实现权限控制
    Sql Server 2008 R2 查询一个实例中存在某个表的数据库
    使用sqlcmd执行连接的时候一直报有语法错误
    Linux信号
    记一次内存爆涨分析 , JVM命令使用
    Java,List操作技巧
  • 原文地址:https://www.cnblogs.com/yirancao/p/7474996.html
Copyright © 2020-2023  润新知