React props传变量

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/react.js"></script>
<script src="js/react-dom.js"></script>
<script src="js/browser.min.js"></script>
</head>
<body>
<div id="example"></div>

<script type="text/babel">
var LabelComponent = React.createClass({
render:function(){
return <label>{this.props.labelName}</label>
}
})

var InputComponent = React.createClass({
render:function(){
return <input type="text" placeholder={this.props.tips}/>
}
})

var ButtonComponent = React.createClass({
render:function(){
return <button>{this.props.buttonName}</button>
}
})

var LoginWindow = React.createClass({
render:function(){
return <div>
<LabelComponent labelName='用户名'/>
<InputComponent tips='请输入用户名'/>
<br/>
<LabelComponent labelName='密码'/>
<InputComponent tips='请输入密码'/>
<br/>
<ButtonComponent buttonName='注册'></ButtonComponent>
<ButtonComponent buttonName='登录'></ButtonComponent>
</div>
}
})

ReactDOM.render(
<LoginWindow/>,
document.getElementById('example')
)

</script>

</body>
</html>
posted @ 2017-08-09 09:20  ThisCall  阅读(393)  评论(0编辑  收藏  举报