<!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>