{"id":27215,"date":"2024-11-24T13:15:16","date_gmt":"2024-11-24T05:15:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27215\/"},"modified":"2024-11-24T13:15:16","modified_gmt":"2024-11-24T05:15:16","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-react-%e6%8c%89%e9%92%ae%e7%82%b9%e5%87%bb%e6%97%a0%e5%93%8d%e5%ba%94%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27215\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 React \u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121201022006.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 React \u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 React \u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\u306e\u539f\u56e0<\/strong><\/p>\n<p>\u5728\u63d0\u4f9b\u7684 React \u4ee3\u7801\u4e2d\uff0c\u60a8\u4f7f\u7528\u7684\u662f handleClick \u51fd\u6570\u4f5c\u4e3a\u6309\u94ae\u7684 onClick \u5904\u7406\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\u6ca1\u6709\u5b9a\u4e49\u6b64\u51fd\u6570\u3002\u8fd9\u4f1a\u5bfc\u81f4\u6309\u94ae\u5728\u70b9\u51fb\u65f6\u6ca1\u6709\u54cd\u5e94\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4fee\u590d\u6b64\u95ee\u9898\uff1a<\/p>\n<pre>import React from 'react'\n\nfunction App5() {\n  \/\/ \u5b9a\u4e49 handleClick \u51fd\u6570\n  const handleClick = () =&gt; {\n    console.log(123)\n  }\n\n  return (\n    &lt;div\n      style={{ position: 'relative', height: '100vh' }}\n    &gt;\n      &lt;div id=\"header\" style={{ width: '100%', height: '24px', backgroundColor: '#ddd',\n        display: 'flex', justifyContent: 'flex-end'\n    }}&gt;\n        {\/* Q1: \u5982\u4f55\u8ba9\u533a\u57df1 \u5728\u4e2d\u95f4\u5462\uff1f *\/}\n          &lt;span style={{ margin: '0 auto' }}&gt;\u533a\u57df1&lt;\/span&gt;  \n\n        {\/* Q2: \u6ca1\u6709\u54cd\u5e94\u70b9\u51fb\u4e8b\u4ef6 *\/}\n          &lt;button \n            onClick={ handleClick }\n          &gt;\u5f00\u5173&lt;\/button&gt;\n      &lt;\/div&gt;\n      &lt;div id=\"content\" style={{  position: 'absolute', top: '24', bottom: '24px', width: '100%', height: '100%' }}&gt;&lt;\/div&gt;\n      &lt;div id=\"footer\" style={{  position: 'absolute', bottom: 0, width: '100%', height: '24px', backgroundColor: '#3472BB' }}&gt;&lt;\/div&gt;\n    &lt;\/div&gt;\n  )\n}\n\nexport default App5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u5916\uff0c\u60a8\u7684\u4ee3\u7801\u4e2d\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5728 span \u5143\u7d20\u4e2d\uff0c\u60a8\u6ca1\u6709\u6307\u5b9a\u4efb\u4f55\u6837\u5f0f\u6765\u4f7f\u5176\u5c45\u4e2d\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u5728 style \u5c5e\u6027\u4e2d\u6dfb\u52a0 margin: 0 auto;\u3002<\/li>\n<li>\u60a8\u6ca1\u6709\u4f7f\u7528 border-radius \u5c5e\u6027\u6765\u8bbe\u7f6e\u6309\u94ae\u5706\u89d2\u3002\u5982\u679c\u60a8\u5e0c\u671b\u6309\u94ae\u4e3a\u5706\u5f62\uff0c\u53ef\u4ee5\u6dfb\u52a0 border-radius: 50%; \u5230\u6309\u94ae\u7684 style \u5c5e\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f React \u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\u306e\u539f\u56e0 \u5728\u63d0\u4f9b\u7684 React \u4ee3\u7801\u4e2d\uff0c\u60a8\u4f7f\u7528\u7684\u662f handleClick \u51fd\u6570\u4f5c\u4e3a\u6309\u94ae\u7684 onClick \u5904\u7406\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\u6ca1\u6709\u5b9a\u4e49\u6b64\u51fd\u6570\u3002\u8fd9\u4f1a\u5bfc\u81f4\u6309\u94ae\u5728\u70b9\u51fb\u65f6\u6ca1\u6709\u54cd\u5e94\u3002 \u4ee5\u4e0b\u662f\u5982\u4f55\u4fee\u590d\u6b64\u95ee\u9898\uff1a import React from &#8216;react&#8217; function App5() { \/\/ \u5b9a\u4e49 handleClick \u51fd\u6570 const handleClick = () =&gt; { console.log(123) } return ( &lt;div style={{ position: &#8216;relative&#8217;, height: &#8216;100vh&#8217; }} &gt; &lt;div id=&#8221;header&#8221; style={{ width: &#8216;100%&#8217;, height: &#8217;24px&#8217;, backgroundColor: &#8216;#ddd&#8217;, display: &#8216;flex&#8217;, justifyContent: &#8216;flex-end&#8217; }}&gt; {\/* Q1: \u5982\u4f55\u8ba9\u533a\u57df1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27215","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27215"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27215\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}