{"id":617,"date":"2016-06-29T16:35:58","date_gmt":"2016-06-29T08:35:58","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=617"},"modified":"2016-06-29T16:35:58","modified_gmt":"2016-06-29T08:35:58","slug":"react%e5%bc%80%e5%8f%91%e8%bf%9b%e9%98%b6%e4%b9%8bjsx%e8%af%ad%e6%b3%95%e5%92%8creact%e7%bb%84%e4%bb%b6%e7%9a%84%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=617","title":{"rendered":"React\u5f00\u53d1\u8fdb\u9636\u4e4bJSX\u8bed\u6cd5\u548cReact\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f"},"content":{"rendered":"<blockquote>\n<p>\n\t\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u6240\u6709\u5929\u4e0a\u98de\u7684\u7406\u5ff5\uff0c\u90fd\u9700\u8981\u9646\u5730\u4e0a\u5b9e\u73b0\u3002\u968f\u7740React\u706b\u4e86\u4e4b\u540e\uff0cReact\u73b0\u5728\u5df2\u6210\u4e86\u524d\u7aef\u5f00\u53d1\u7684\u5fc5\u5b66\u6846\u67b6\u4e86\u3002\u800c\u4e14React\u7684\u5b9e\u73b0\u601d\u60f3\u8fd8\u662f\u90a3\u4e48\u7684\u72ec\u7279\uff0c\u5bf9\u6211\u4eec\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\u524d\u7aef\u5f00\u53d1\u53ef\u4ee5\u6253\u4e0b\u575a\u5b9e\u7684\u57fa\u7840\u3002\u5979\u5bf9DOM\u64cd\u4f5c\u7684\u865a\u62dfDOM(virtual-dom)\u673a\u5236\uff0c\u662f\u672a\u6765\u524d\u7aef\u53d1\u5c55\u7684\u4e00\u5927\u65b9\u5411\uff01<\/span>\n\t<\/p>\n<\/blockquote>\n<h2>\n\tReact\u5f00\u53d1\u5b9e\u6218<br \/>\n<\/h2>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">React\u6846\u67b6\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u5728Web\u9875\u9762\u4e2d\u5f15\u7528react.js\u548cJSXTransformer.js\u8fd9\u4e24\u4e2ajs\u6587\u4ef6\u5c31\u53ef\u4ee5\u5feb\u901f\u5f00\u59cb\u4e86\u3002<\/span>\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;meta charset=&quot;UTF-8&quot; \/&gt;\r\n    &lt;title&gt;Hello React!&lt;\/title&gt;\r\n    &lt;script src=&quot;build\/react.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script src=&quot;build\/react-dom.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script src=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/babel-core\/5.8.23\/browser.min.js&quot;&gt;&lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id=&quot;xttblog&quot;&gt;&lt;\/div&gt;\r\n    &lt;script type=&quot;text\/babel&quot;&gt;\r\n      ReactDOM.render(\r\n        &lt;h1&gt;www.xttblog.com&lt;\/h1&gt;,\r\n        document.getElementById(&#039;xttblog&#039;)\r\n      );\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u770b\u4e86demo\u53ef\u80fd\u5927\u5bb6\u611f\u89c9\u5947\u602a\u7684\u662f&lt;script type=&quot;text\/babel&quot;&gt;\uff0c\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u53d8\u4e86\u5462\uff1f\u8fd9\u662f\u4e3a\u4e86\u628aJSX\u8f6c\u6210\u6807\u51c6\u7684JavaScript\uff0c\u6211\u4eec\u5c31\u7528\u4e86&lt;script type=&quot;text\/babel&quot;&gt;\u6807\u7b7e\uff0c\u7136\u540e\u901a\u8fc7Babel\u8f6c\u6362\u6210\u5728\u6d4f\u89c8\u5668\u4e2d\u771f\u6b63\u6267\u884c\u7684\u5185\u5bb9\u3002\u540c\u6837\u7684\u6211\u4eec\u53ef\u80fd\u8fd8\u4f1a\u89c1\u5230&lt;script type=&quot;text\/jsx&quot;&gt;\u6807\u7b7e\uff0c\u8fd9\u662f\u56e0\u4e3aReact\u72ec\u6709\u7684JSX\u8bed\u6cd5\uff0c\u8ddfJavaScript\u4e0d\u517c\u5bb9\u3002React\u63d0\u4f9b\u4e24\u4e2a\u5e93\uff1areact.js\u548cJSXTransformer.js \uff0c\u5b83\u4eec\u5fc5\u987b\u9996\u5148\u52a0\u8f7d\u3002\u5728\u5b9e\u9645\u7684\u751f\u6210\u8fc7\u7a0b\u4e2dJSXTransformer.js\u662f\u5728\u670d\u52a1\u5668\u7aef\u5148\u5b8c\u6210\u7684\u3002<\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">react\u5e76\u4e0d\u4f9d\u8d56jQuery\uff0c\u5f53\u7136\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528jQuery\uff0c\u4f46\u662frender\u91cc\u9762\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u4f7f\u7528JavaScript\u539f\u751f\u7684getElementByID\u65b9\u6cd5\uff0c\u4e0d\u80fd\u4f7f\u7528jQuery\u6765\u9009\u53d6DOM\u8282\u70b9\u3002<\/span>\n<\/p>\n<h2>\n\tJsx\u8bed\u6cd5<br \/>\n<\/h2>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u901a\u8fc7\u4e0a\u9762\u7684demo\uff0c\u6211\u4eec\u53d1\u73b0HTML\u8bed\u8a00\u76f4\u63a5\u5199\u5728JavaScript\u8bed\u8a00\u4e4b\u4e2d\uff0c\u4e0d\u52a0\u4efb\u4f55\u5f15\u53f7\uff0c\u8fd9\u5c31\u662fJSX\u7684\u8bed\u6cd5\uff0c\u5b83\u5141\u8bb8HTML\u4e0eJavaScript\u7684\u6df7\u5199\uff0c\u4e86\u89e3\u8fc7AngularJs\u7684\u670b\u53cb\u4e5f\u4f1a\u53d1\u73b0React\u540c\u6837\u7684\u4f7f\u7528{x}\u7ed3\u6784\u6765\u64cd\u4f5c\u53d8\u91cf\u3002<\/span>\n<\/p>\n<h2>\n\tReact\u7ec4\u4ef6\u5c5e\u6027<br \/>\n<\/h2>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">ReactJS\u662f\u57fa\u4e8e\u7ec4\u4ef6\u5316\u7684\u5f00\u53d1\uff0cReact\u5141\u8bb8\u5c06\u4ee3\u7801\u5c01\u88c5\u6210\u7ec4\u4ef6\uff08component\uff09\uff0c\u7136\u540e\u50cf\u63d2\u5165\u666e\u901aHTML\u6807\u7b7e\u4e00\u6837\uff0c\u5728\u7f51\u9875\u4e2d\u63d2\u5165\u8fd9\u4e2a\u7ec4\u4ef6\u3002React.createClass\u65b9\u6cd5\u5c31\u7528\u4e8e\u751f\u6210\u4e00\u4e2a\u7ec4\u4ef6\u7c7b\u3002<\/span>\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar Xttblog = React.createClass({\r\n\trender:function(){\r\n\t\treturn &lt;h1&gt;www.xttblog.com {test}&lt;\/h1&gt;;\r\n\t}\r\n});\r\nReact.render(\r\n\t&lt;Xttblog test=&quot;\u4e1a\u4f59\u8349&quot; \/&gt;,\r\n\tdocument.getElementById(&#039;container&#039;)\r\n);<\/pre>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u6839\u636e\u4e0a\u9762\u7684\u4ee3\u7801\u6211\u4eec\u987a\u4fbf\u603b\u7ed3\u4e0bReact\u7ec4\u4ef6\uff1a<\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\"><span style=\"color:#000080\">1\uff09\u83b7\u53d6\u5c5e\u6027\u7684\u503c\u7528\u7684\u662fthis.props.\u5c5e\u6027\u540d<br \/>\n\t2\uff09\u521b\u5efa\u7684\u7ec4\u4ef6\u540d\u79f0\u9996\u5b57\u6bcd\u5fc5\u987b\u5927\u5199\u3002<br \/>\n\t3\uff09\u4e3a\u5143\u7d20\u6dfb\u52a0css\u7684class\u65f6\uff0c\u8981\u7528className\u3002<br \/>\n\t4\uff09\u7ec4\u4ef6\u7684style\u5c5e\u6027\u7684\u8bbe\u7f6e\u65b9\u5f0f\u4e5f\u503c\u5f97\u6ce8\u610f\uff0c\u8981\u5199\u6210style={{width: this.state.witdh}}\u3002<\/span><\/span>\n<\/p>\n<h2>\n\tReact\u7ec4\u4ef6\u72b6\u6001<br \/>\n<\/h2>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u7ec4\u4ef6\u514d\u4e0d\u4e86\u8981\u4e0e\u7528\u6237\u4e92\u52a8\uff0cReact\u7684\u4e00\u5927\u521b\u65b0\u5c31\u662f\u5c06\u7ec4\u4ef6\u770b\u6210\u662f\u4e00\u4e2a\u72b6\u6001\u673a\u3002\u4e00\u5f00\u59cb\u6709\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\uff0c\u7136\u540e\u7528\u6237\u4e92\u52a8\uff0c\u5bfc\u81f4\u72b6\u6001\u53d8\u5316\uff0c\u4ece\u800c\u89e6\u53d1\u91cd\u65b0\u6e32\u67d3UI\u3002\u7ec4\u4ef6\u72b6\u6001\u7684\u5f00\u53d1\u6211\u4eec\u4e00\u822c\u8981\u7528\u5230getInitialState\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u5728\u7ec4\u4ef6\u521d\u59cb\u5316\u7684\u65f6\u5019\u6267\u884c\uff0c\u5fc5\u9700\u8fd4\u56deNULL\u6216\u8005\u4e00\u4e2a\u5bf9\u8c61\u3002\u5173\u4e8e\u7ec4\u4ef6\u72b6\u6001\u7684\u4f7f\u7528\u4e00\u822c\u4f53\u73b0\u5728UI\u7684\u542f\u7528\u3001\u7981\u7528\uff0c\u663e\u793a\u3001\u9690\u85cf\u7b49\u65b9\u9762\u3002<\/span>\n<\/p>\n<h2>\n\tReact\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f<br \/>\n<\/h2>\n<p>\n\t<span style=\"font-size:14px;font-family: 'Microsoft YaHei' ! important\">\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\u5206\u6210\u4e09\u4e2a\u72b6\u6001\uff1a<br \/>\n\t<strong>Mounting<\/strong>\uff1a<span style=\"color:#000080\">\u5df2\u63d2\u5165\u771f\u5b9e DOM<\/span><br \/>\n\t<strong>Updating<\/strong>\uff1a<span style=\"color:#000080\">\u6b63\u5728\u88ab\u91cd\u65b0\u6e32\u67d3<\/span><br \/>\n\t<strong>Unmounting<\/strong>\uff1a<span style=\"color:#000080\">\u5df2\u79fb\u51fa\u771f\u5b9e DOM<\/span><br \/>\n\tReact \u4e3a\u6bcf\u4e2a\u72b6\u6001\u90fd\u63d0\u4f9b\u4e86\u4e24\u79cd\u5904\u7406\u51fd\u6570\uff0cwill \u51fd\u6570\u5728\u8fdb\u5165\u72b6\u6001\u4e4b\u524d\u8c03\u7528\uff0cdid \u51fd\u6570\u5728\u8fdb\u5165\u72b6\u6001\u4e4b\u540e\u8c03\u7528\uff0c\u4e09\u79cd\u72b6\u6001\u5171\u8ba1\u4e94\u79cd\u5904\u7406\u51fd\u6570\u3002<br \/>\n\t<span style=\"color:#4B0082\">componentWillMount()<br \/>\n\tcomponentDidMount()<br \/>\n\tcomponentWillUpdate(object nextProps, object nextState)<br \/>\n\tcomponentDidUpdate(object prevProps, object prevState)<br \/>\n\tcomponentWillUnmount()<\/span><br \/>\n\t\u6b64\u5916\uff0cReact \u8fd8\u63d0\u4f9b\u4e24\u79cd\u7279\u6b8a\u72b6\u6001\u7684\u5904\u7406\u51fd\u6570\u3002<br \/>\n\t<span style=\"color:#B22222\">componentWillReceiveProps(object nextProps)\uff1a\u5df2\u52a0\u8f7d\u7ec4\u4ef6\u6536\u5230\u65b0\u7684\u53c2\u6570\u65f6\u8c03\u7528<br \/>\n\tshouldComponentUpdate(object nextProps, object nextState)\uff1a\u7ec4\u4ef6\u5224\u65ad\u662f\u5426\u91cd\u65b0\u6e32\u67d3\u65f6\u8c03\u7528<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px;font-family: 'Microsoft YaHei' ! important\"><strong>\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u672a\u7ecf\u535a\u4e3b\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002<\/strong><\/span><\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=617\">React\u5f00\u53d1\u8fdb\u9636\u4e4bJSX\u8bed\u6cd5\u548cReact\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6240\u6709\u5929\u4e0a\u98de\u7684\u7406\u5ff5\uff0c\u90fd\u9700\u8981\u9646\u5730\u4e0a\u5b9e\u73b0\u3002\u968f\u7740React\u706b\u4e86\u4e4b\u540e\uff0cReact\u73b0\u5728\u5df2\u6210\u4e86\u524d\u7aef\u5f00\u53d1\u7684\u5fc5\u5b66\u6846\u67b6\u4e86\u3002\u800c\u4e14Re [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[377,373,379,378],"class_list":["post-617","post","type-post","status-publish","format-standard","hentry","category-html5","tag-jsx","tag-react"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=617"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions"}],"predecessor-version":[{"id":618,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions\/618"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}