首页 > 代码库 > React实例3-状态2
React实例3-状态2
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>state2</title>
<script src="http://www.mamicode.com/build/browser.min.js"></script>
<script src="http://www.mamicode.com/build/react.js"></script>
<script src="http://www.mamicode.com/build/react-dom.js"></script>
<script type="text/babel">
var ClickApp = React.createClass({
getInitialState:function(){
return {
clickCount:0,
};
},
handleClick:function(){
this.setState({
clickCount:this.state.clickCount+1,
});
},
render:function(){
return (
<div>
<h2>点击下面按钮</h2>
<button onClick={this.handleClick}>点击我</button>
<p>你一共点击了:{this.state.clickCount}</p>
</div>
);
}
});
ReactDOM.render(<ClickApp/>,
document.getElementById(‘app‘),
function(){
console.log(‘渲染完成啦‘)
});
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
React实例3-状态2