标签:一个 struct 标签 参数 fragment ESS rop obs click
1 <Fragment> 2 <one val={message}></one> 3 </Fragment>
1 render(){ 2 let {val} = this.props; 3 return ( 4 <Fragment> 5 <div>接收来自父组件的传值:{val}</div> 6 </Fragment> 7 ) 8 }
1 render(){ 2 return ( 3 <Fragment> 4 <one send={this.handleRevese.bind(this)}></one> 5 </Fragment> 6 ) 7 } 8 9 handleRevese(params){ 10 console.log(‘来自子组件的传值‘ + params); 11 }
1 render(){ 2 return ( 3 <Fragment> 4 <button onClick={this.handleSend.bind(this)}>向父组件传值</button> 5 </Fragment> 6 ) 7 } 8 9 handleSend(){ 10 this.props.send(this.state.mess); 11 }
1 render(){ 2 return ( 3 <div> 4 <button onClick={this.handleTwo.bind(this)}>发送给Two组件</button> 5 </div> 6 ) 7 } 8 9 handleTwo(){ 10 Observer.$emit("handle",this.state.oneVal); 11 }
1 constructor(){ 2 super(); 3 this.state = { 4 oneVal:"" 5 } 6 Observer.$on("handle",(val)=>{ 7 this.setState({ 8 oneVal:val 9 }) 10 }) 11 } 12 13 render(){ 14 let {oneVal} = this.state; 15 return ( 16 <div>接收到one组件的值为:{oneVal}</div> 17 ) 18 }
标签:一个 struct 标签 参数 fragment ESS rop obs click
原文地址:https://www.cnblogs.com/jokehl/p/9998163.html