加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React.js的HelloWorld示例

发布时间:2020-12-15 04:53:16 所属栏目:百科 来源:网络整理
导读:近一段时间,由于新的项目中要使用React.js,所以找周末的时间稍微看了一下,下面是一个简单地HelloWorld的示例: !DOCTYPE html html head titleHelloWorld/title !-- Not present in the tutorial. Just for basic styling. -- link rel="stylesheet" href

近一段时间,由于新的项目中要使用React.js,所以找周末的时间稍微看了一下,下面是一个简单地HelloWorld的示例:

<!DOCTYPE html>
<html>
<head>
<title>HelloWorld</title>
<!-- Not present in the tutorial. Just for basic styling. -->
<link rel="stylesheet" href="css/base.css" />
<script src="react.js"></script>
<script src="JSXTransformer.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="content"></div>
<script type="text/jsx">

var HelloText = React.createClass({
render: function() {
return (
<div>
<h3>Hello,{this.props.data}</h3>
</div>
);
}
});

React.render(<HelloText data="World!" />,document.getElementById('content')); </script>
</body>
</html>

其实上边示例看似简单,其实它隐藏了ReactJs的很多细节,比如像props来获取属性data的值,要想更深入的学习ReactJS,必须对props以及state有一个清晰的认识。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读