@2890594972
2018-05-04T04:37:20.000000Z
字数 1037
阅读 775
react
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>子组件向父组件传递参数</title>
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var Content = React.createClass({
sendFather: function(event){
this.props.updateStateProp(event, 'hello world', 'daxiang');
},
render: function() {
return <div>
<button onClick = {this.sendFather}>点我</button>
<h4>{this.props.myDataProp}</h4>
</div>
}
});
var HelloMessage = React.createClass({
getInitialState: function() {
return {value: 'Hello Runoob!'};
},
handleChange: function(event, str) {
console.log(arguments)
this.setState({value: '菜鸟教程'})
},
render: function() {
var value = this.state.value;
return <div>
<Content myDataProp = {value}
updateStateProp = {this.handleChange}></Content>
</div>;
}
});
ReactDOM.render(
<HelloMessage />,
document.getElementById('example')
);
</script>
</body>
</html>