React this.state

前端之家收集整理的这篇文章主要介绍了React this.state前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!doctype html>
<html>
<head>
		<Meta charset="utf-8">
	
	<script src="../build/react.js"></script>
	<script src="../build/react-dom.js"></script>
	<script src="../build/browser.min.js"></script>
</head>
<body>
	<div id="abc"></div>
	<script type="text/babel">
		
		var LikeButton = React.createClass({
			getInitialState:function(){<!--初始化状态值-->
				return {liked:true};
			},handleClick:function(event){<!--处理函数 不断的取反-->
				this.setState({liked: !this.state.liked});
			},render:function(){
				var text=this.state.liked? 'liked':'havent liked';
				return (
					<p onClick={this.handleClick}>
						you {text} this.Click to toggle.
					</p>
				);
			}
		});
		

		ReactDOM.render(
		<LikeButton />,document.getElementById('abc')
		);
	</script>
</body>
</html>

原文链接:https://www.f2er.com/react/303889.html

猜你在找的React相关文章