{"id":207522,"date":"2020-12-23T09:13:08","date_gmt":"2020-12-23T01:13:08","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=207522"},"modified":"2020-12-21T10:14:30","modified_gmt":"2020-12-21T02:14:30","slug":"react-study-components","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/react-study-components.html","title":{"rendered":"React\u5b66\u4e60\u7b14\u8bb0-\u7ec4\u4ef6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nReact \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa\u7528\u6237\u754c\u9762\u7684 JAVASCRIPT \u5e93\u3002React \u4e3b\u8981\u7528\u4e8e\u6784\u5efaUI\uff0c\u5f88\u591a\u4eba\u8ba4\u4e3a React \u662f MVC \u4e2d\u7684 V\uff08\u89c6\u56fe\uff09\u3002React \u8d77\u6e90\u4e8e Facebook \u7684\u5185\u90e8\u9879\u76ee\uff0c\u7528\u6765\u67b6\u8bbe Instagram \u7684\u7f51\u7ad9\uff0c\u5e76\u4e8e 2013 \u5e74 5 \u6708\u5f00\u6e90\u3002React \u62e5\u6709\u8f83\u9ad8\u7684\u6027\u80fd\uff0c\u4ee3\u7801\u903b\u8f91\u975e\u5e38\u7b80\u5355\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4eba\u5df2\u5f00\u59cb\u5173\u6ce8\u548c\u4f7f\u7528\u5b83\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\n\u672c\u7ae0\u8282\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528\u7ec4\u4ef6\u4f7f\u5f97\u6211\u4eec\u7684\u5e94\u7528\u66f4\u5bb9\u6613\u6765\u7ba1\u7406\u3002
\n\u63a5\u4e0b\u6765\u6211\u4eec\u5c01\u88c5\u4e00\u4e2a\u8f93\u51fa \"Hello World\uff01\" \u7684\u7ec4\u4ef6\uff0c\u7ec4\u4ef6\u540d\u4e3a HelloMessage\uff1a<\/p>\n

React \u5b9e\u4f8b<\/p>\n

\r\nfunction HelloMessage(props) {\r\n    return <h1>Hello World!<\/h1>;\r\n}\r\n \r\nconst element = <HelloMessage \/>;\r\n \r\nReactDOM.render(\r\n    element,\r\n    document.getElementById('example')\r\n);<\/pre>\n
\u5b9e\u4f8b\u89e3\u6790\uff1a<\/strong><\/div>\n

1\u3001\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n

\r\nfunction HelloMessage(props) {\r\n    return <h1>Hello World!<\/h1>;\r\n}<\/pre>\n

\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 ES6 class \u6765\u5b9a\u4e49\u4e00\u4e2a\u7ec4\u4ef6:<\/p>\n

\r\nclass Welcome extends React.Component {\r\n  render() {\r\n    return <h1>Hello World!<\/h1>;\r\n  }\r\n}<\/pre>\n

2\u3001const element = <HelloMessage \/> \u4e3a\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u7ec4\u4ef6\u3002<\/p>\n

\u6ce8\u610f\uff0c\u539f\u751f HTML \u5143\u7d20\u540d\u4ee5\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u800c\u81ea\u5b9a\u4e49\u7684 React \u7c7b\u540d\u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u6bd4\u5982 HelloMessage \u4e0d\u80fd\u5199\u6210 helloMessage\u3002\u9664\u6b64\u4e4b\u5916\u8fd8\u9700\u8981\u6ce8\u610f\u7ec4\u4ef6\u7c7b\u53ea\u80fd\u5305\u542b\u4e00\u4e2a\u9876\u5c42\u6807\u7b7e\uff0c\u5426\u5219\u4e5f\u4f1a\u62a5\u9519\u3002<\/p>\n

\u5982\u679c\u6211\u4eec\u9700\u8981\u5411\u7ec4\u4ef6\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 this.props \u5bf9\u8c61,\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/p>\n

React \u5b9e\u4f8b<\/p>\n

\r\nfunction HelloMessage(props) {\r\n    return <h1>Hello {props.name}!<\/h1>;\r\n}\r\n \r\nconst element = <HelloMessage name=\"Runoob\"\/>;\r\n \r\nReactDOM.render(\r\n    element,\r\n    document.getElementById('example')\r\n);\r\n<\/pre>\n

\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d name \u5c5e\u6027\u901a\u8fc7 props.name \u6765\u83b7\u53d6\u3002
\n\u6ce8\u610f\uff0c\u5728\u6dfb\u52a0\u5c5e\u6027\u65f6\uff0c class \u5c5e\u6027\u9700\u8981\u5199\u6210 className \uff0cfor \u5c5e\u6027\u9700\u8981\u5199\u6210 htmlFor \uff0c\u8fd9\u662f\u56e0\u4e3a class \u548c for \u662f JavaScript \u7684\u4fdd\u7559\u5b57\u3002<\/p>\n

\u590d\u5408\u7ec4\u4ef6<\/strong><\/div>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u591a\u4e2a\u7ec4\u4ef6\u6765\u5408\u6210\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u5373\u628a\u7ec4\u4ef6\u7684\u4e0d\u540c\u529f\u80fd\u70b9\u8fdb\u884c\u5206\u79bb\u3002
\n\u4ee5\u4e0b\u5b9e\u4f8b\u6211\u4eec\u5b9e\u73b0\u4e86\u8f93\u51fa\u7f51\u7ad9\u540d\u5b57\u548c\u7f51\u5740\u7684\u7ec4\u4ef6\uff1a<\/p>\n

React \u5b9e\u4f8b<\/p>\n

\r\nfunction Name(props) {\r\n    return <h1>\u7f51\u7ad9\u540d\u79f0\uff1a{props.name}<\/h1>;\r\n}\r\nfunction Url(props) {\r\n    return <h1>\u7f51\u7ad9\u5730\u5740\uff1a{props.url}<\/h1>;\r\n}\r\nfunction Nickname(props) {\r\n    return <h1>\u7f51\u7ad9\u5c0f\u540d\uff1a{props.nickname}<\/h1>;\r\n}\r\nfunction App() {\r\n    return (\r\n    <div>\r\n        <Name name=\"Linux\u5c31\u8be5\u8fd9\u4e48\u5b66\" \/>\r\n        <Url url=\"http:\/\/lrxjmw.cn\" \/>\r\n        <Nickname nickname=\"Runoob\" \/>\r\n    <\/div>\r\n    );\r\n}\r\n \r\nReactDOM.render(\r\n     <App \/>,\r\n    document.getElementById('example')\r\n);<\/pre>\n

\u5b9e\u4f8b\u4e2d App \u7ec4\u4ef6\u4f7f\u7528\u4e86 Name\u3001Url \u548c Nickname \u7ec4\u4ef6\u6765\u8f93\u51fa\u5bf9\u5e94\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u7ae0\u8282\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528\u7ec4\u4ef6\u4f7f\u5f97\u6211\u4eec\u7684\u5e94\u7528\u66f4\u5bb9\u6613\u6765\u7ba1\u7406\u3002 \u63a5\u4e0b\u6765\u6211\u4eec\u5c01\u88c5\u4e00\u4e2a\u8f93\u51fa “Hello World\uff01” […]<\/p>\n","protected":false},"author":1470,"featured_media":207359,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-207522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=207522"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522\/revisions"}],"predecessor-version":[{"id":207525,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522\/revisions\/207525"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/207359"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=207522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=207522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=207522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}