import React from 'react';
import B from './B';
class A extends React.Component{
    state = {
        msg:'我来自于A组件'
    }
    isClick=(value)=> {
        this.setState({
            msg: value
        })
    }
    render() {
        return (
            <div>
                我是A组件:

                <hr />
                <B msg={this.state.msg} myClick={this.isClick}/>
            </div>

        )
    }
}

export default A;
import React from 'react';

class B extends React.Component{
    constructor(props) {
        super(props)
    }
    render() {
        return (
            <div>
                <h2>我是B组件:{this.props.msg}</h2>
                <button onClick={() => this.props.myClick('我来源于B组件')}>按钮</button>
            </div>
        )
    }
}

export default B;

 

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-09-28
  • 2022-02-02
  • 2021-11-14
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2018-03-06
  • 2021-06-25
  • 2021-05-08
相关资源
相似解决方案