{"id":53634,"date":"2024-12-03T12:22:32","date_gmt":"2024-12-03T04:22:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53634\/"},"modified":"2024-12-03T12:22:32","modified_gmt":"2024-12-03T04:22:32","slug":"%e5%9f%ba%e4%ba%8e%e7%bb%84%e4%bb%b6%e7%9a%84%e6%9e%b6%e6%9e%84%e7%9a%84%e5%85%b3%e9%94%ae%e7%89%b9%e5%be%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53634\/","title":{"rendered":"\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733151110674dc986b979e.jpg\" class=\"aligncenter\" title=\"\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81\u63d2\u56fe\" alt=\"\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81\u63d2\u56fe\" \/><\/p>\n<p>\u4ee5\u4e0b\u662f\u5728 react js \u4e2d\u5b9e\u73b0\u7684 <strong>\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784<\/strong> \u7684 5 \u4e2a\u5173\u952e\u7279\u5f81\u3002\u8fd9\u4e9b\u793a\u4f8b\u5c06\u6f14\u793a react \u7ec4\u4ef6\u5982\u4f55\u4f53\u73b0 <\/p>\n<p> \u7684\u7279\u6027 <\/p>\n<ol>\n<li>\u53ef\u91cd\u590d\u4f7f\u7528\u6027<\/li>\n<li>\u5c01\u88c5\u6027\u3001\u4e92\u6362\u6027<\/li>\n<li>\u53ef\u6269\u5c55\u6027<\/li>\n<li>\u53ef\u7ef4\u62a4\u6027<\/li>\n<li>\u6784\u56fe<\/li>\n<\/ol>\n<p><strong>\u53ef\u91cd\u7528\u6027<\/strong><br \/> \u7ec4\u4ef6\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u4e0d\u540c\u90e8\u5206\u91cd\u590d\u4f7f\u7528\u3002<br \/> \u793a\u4f8b\uff1a\u591a\u6b21\u4f7f\u7528\u7684 button \u7ec4\u4ef6<\/p>\n<pre>function button({ label, onclick }) {\n  return &lt;button onclick={onclick}&gt;{label}&lt;\/button&gt;;\n}\n\nfunction app() {\n  return (\n    &lt;div&gt;\n      &lt;button label=\"submit\" onclick={() =&gt; alert('submit clicked')} \/&gt;\n      &lt;button label=\"cancel\" onclick={() =&gt; alert('cancel clicked')} \/&gt;\n    &lt;\/div&gt;\n  );\n}\n<\/pre>\n<p><strong>\u5c01\u88c5<\/strong><br \/> \u7ec4\u4ef6\u5c01\u88c5\u4e86\u81ea\u5df1\u7684\u903b\u8f91\u548c\u6837\u5f0f\uff0c\u9632\u6b62\u5916\u754c\u5e72\u6270\u3002<br \/> \u793a\u4f8b\uff1a\u5c01\u88c5\u7528\u6237\u6570\u636e\u7684 userprofile \u7ec4\u4ef6<\/p>\n<pre>function userprofile({ name, email }) {\n  return (\n    &lt;div&gt;\n      &lt;h3&gt;{name}&lt;\/h3&gt;\n      &lt;p&gt;email: {email}&lt;\/p&gt;\n    &lt;\/div&gt;\n  );\n}\n\nfunction app() {\n  return (\n    &lt;userprofile name=\"john doe\" email=\"john@example.com\" \/&gt;\n  );\n}\n<\/pre>\n<p><strong>\u4e92\u6362\u6027<\/strong><br \/> \u53ef\u4ee5\u4ea4\u6362\u6216\u66ff\u6362\u7ec4\u4ef6\uff0c\u800c\u4e0d\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u7684\u6574\u4f53\u529f\u80fd\u3002<br \/> \u793a\u4f8b\uff1a\u5c06 primarybutton \u4e0e secondarybutton \u4ea4\u6362<\/p>\n<pre>function primarybutton({ label, onclick }) {\n  return &lt;button style={{ backgroundcolor: 'blue', color: 'white' }} onclick={onclick}&gt;{label}&lt;\/button&gt;;\n}\n\nfunction secondarybutton({ label, onclick }) {\n  return &lt;button style={{ backgroundcolor: 'gray', color: 'white' }} onclick={onclick}&gt;{label}&lt;\/button&gt;;\n}\n\nfunction app({ useprimary }) {\n  return (\n    &lt;div&gt;\n      {useprimary ? &lt;primarybutton label=\"click me\" onclick={() =&gt; alert('primary clicked')} \/&gt; : \n                   &lt;secondarybutton label=\"click me\" onclick={() =&gt; alert('secondary clicked')} \/&gt;}\n    &lt;\/div&gt;\n  );\n}\n<\/pre>\n<p><strong>\u53ef\u6269\u5c55\u6027<\/strong><br \/> \u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\u6765\u8f7b\u677e\u6269\u5c55\uff0c\u800c\u4e0d\u5f71\u54cd\u73b0\u6709\u7ec4\u4ef6\u3002<br \/> \u793a\u4f8b\uff1a\u6dfb\u52a0\u66f4\u591a\u4ea7\u54c1\u7ec4\u4ef6\u6765\u6269\u5c55\u5e94\u7528\u7a0b\u5e8f<\/p>\n<pre>function product({ name, price }) {\n  return (\n    &lt;div&gt;\n      &lt;h3&gt;{name}&lt;\/h3&gt;\n      &lt;p&gt;price: ${price}&lt;\/p&gt;\n    &lt;\/div&gt;\n  );\n}\n\nfunction productlist() {\n  const products = [\n    { name: 'iphone 13', price: 999 },\n    { name: 'samsung galaxy s21', price: 799 },\n    { name: 'google pixel 6', price: 599 },\n  ];\n\n  return (\n    &lt;div&gt;\n      {products.map((product, index) =&gt; (\n        &lt;product key={index} name={product.name} price={product.price} \/&gt;\n      ))}\n    &lt;\/div&gt;\n  );\n}\n\nfunction app() {\n  return &lt;productlist \/&gt;;\n}\n<\/pre>\n<p><strong>\u53ef\u7ef4\u62a4\u6027<\/strong><br \/> \u7ec4\u4ef6\u662f\u9694\u79bb\u7684\uff0c\u56e0\u6b64\u53ef\u4ee5\u8f7b\u677e\u5730\u72ec\u7acb\u7ef4\u62a4\u548c\u66f4\u65b0\u3002<br \/> \u793a\u4f8b\uff1a\u66f4\u65b0 product \u7ec4\u4ef6\u800c\u4e0d\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u7684\u5176\u4f59\u90e8\u5206<\/p>\n<pre>function product({ name, price }) {\n  \/\/ add a new feature to show if the product is on sale\n  const isonsale = price &lt; 700;\n  return (\n    &lt;div&gt;\n      &lt;h3&gt;{name}&lt;\/h3&gt;\n      &lt;p&gt;price: ${price} {isonsale &amp;&amp; &lt;span&gt;(on sale!)&lt;\/span&gt;}&lt;\/p&gt;\n    &lt;\/div&gt;\n  );\n}\n\nfunction app() {\n  return (\n    &lt;div&gt;\n      &lt;product name=\"google pixel 6\" price={599} \/&gt;\n    &lt;\/div&gt;\n  );\n}\n<\/pre>\n<p><strong>\u6784\u56fe<\/strong><br \/> \u53ef\u4ee5\u7ec4\u5408\u6216\u7ec4\u5408\u7ec4\u4ef6\u6765\u6784\u5efa\u66f4\u590d\u6742\u7684 ui\u3002<br \/> \u793a\u4f8b\uff1a\u5c06\u9875\u7709\u3001\u4ea7\u54c1\u548c\u9875\u811a\u7ec4\u5408\u5230\u5355\u4e2a\u9875\u9762<\/p>\n<pre>function Header() {\n  return &lt;h1&gt;Welcome to My Shop&lt;\/h1&gt;;\n}\n\nfunction Product({ name, price }) {\n  return (\n    &lt;div&gt;\n      &lt;h3&gt;{name}&lt;\/h3&gt;\n      &lt;p&gt;Price: ${price}&lt;\/p&gt;\n    &lt;\/div&gt;\n  );\n}\n\nfunction Footer() {\n  return &lt;footer&gt;Contact us at shop@example.com&lt;\/footer&gt;;\n}\n\nfunction Page() {\n  return (\n    &lt;div&gt;\n      &lt;Header \/&gt;\n      &lt;Product name=\"Apple Watch\" price={399} \/&gt;\n      &lt;Footer \/&gt;\n    &lt;\/div&gt;\n  );\n}\n\nfunction App() {\n  return &lt;Page \/&gt;;\n}\n<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u638c\u63e1\u79d1\u6280\u672a\u6765\uff1a\u84dd\u5929\u7535\u8111\u7684\u521b\u65b0\u4e0e\u53d1\u5c55\u5168\u666f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81 \u6536\u85cf \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300a\u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784\u7684\u5173\u952e\u7279\u5f81\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 \u4ee5\u4e0b\u662f\u5728 react js \u4e2d\u5b9e\u73b0\u7684 \u57fa\u4e8e\u7ec4\u4ef6\u7684\u67b6\u6784 \u7684 5 \u4e2a\u5173\u952e\u7279\u5f81\u3002\u8fd9\u4e9b\u793a\u4f8b\u5c06\u6f14\u793a react \u7ec4\u4ef6\u5982\u4f55\u4f53\u73b0 \u7684\u7279\u6027 \u53ef\u91cd\u590d\u4f7f\u7528\u6027 \u5c01\u88c5\u6027\u3001\u4e92\u6362\u6027 \u53ef\u6269\u5c55\u6027 \u53ef\u7ef4\u62a4\u6027 \u6784\u56fe \u53ef\u91cd\u7528\u6027 \u7ec4\u4ef6\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u4e0d\u540c\u90e8\u5206\u91cd\u590d\u4f7f\u7528\u3002 \u793a\u4f8b\uff1a\u591a\u6b21\u4f7f\u7528\u7684 button \u7ec4\u4ef6 function button({ label, onclick }) { return &lt;button onclick={onclick}&gt;{label}&lt;\/button&gt;; } function app() { return ( &lt;div&gt; &lt;button label=&#8221;submit&#8221; onclick={() =&gt; alert(&#8216;submit clicked&#8217;)} \/&gt; &lt;button label=&#8221;cancel&#8221; onclick={() =&gt; alert(&#8216;cancel clicked&#8217;)} \/&gt; &lt;\/div&gt; [&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-53634","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53634","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=53634"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53634\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}