首页 > Web开发 > 详细

React基础__初识JSX语法

时间:2019-07-11 16:44:21      阅读:87      评论:0      收藏:0      [点我收藏+]
<script>
var HelloComponent = React.createClass({
  render: function () {
  return <h1>hello world.</h1>
}
})
ReactDOM.render(
  <HelloComponent />,
  document.getElementById(‘reactContainer‘)
)
</script>
 
还可以使用表达式的方式:
可以使用三元表达式,但不接收 if else的方法
<script>
var HelloComponent = React.createClass({
  render: function () {
  return <h1>hello {this.props.name || ‘web-react‘}.</h1>
}
})
ReactDOM.render(
  <HelloComponent name=‘world‘ />,
  document.getElementById(‘reactContainer‘)
)
</script>

React基础__初识JSX语法

原文:https://www.cnblogs.com/sunyang-001/p/11170786.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!