{"id":27650,"date":"2024-11-24T13:38:25","date_gmt":"2024-11-24T05:38:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27650\/"},"modified":"2024-11-24T13:38:25","modified_gmt":"2024-11-24T05:38:25","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8react%e7%bb%84%e4%bb%b6%e5%9c%a8%e5%ae%b9%e5%99%a8%e4%b8%ad%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27650\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528React\u7ec4\u4ef6\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130110389899.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528React\u7ec4\u4ef6\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528React\u7ec4\u4ef6\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7ed9\u5bb9\u5668\u6dfb\u52a0\u884c\u53f7<\/strong><\/p>\n<p>\u5728react\u7ec4\u4ef6\u4e2d\u521b\u5efa\u5f88\u591a\u5c0f\u65b9\u683c\u540e\uff0c\u7531\u4e8e\u9879\u76ee\u7684\u9700\u8981\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u7ed9\u5bb9\u5668\u6dfb\u52a0\u884c\u53f7\u3002<\/p>\n<p>\u5bf9\u4e8e\u5982\u4f55\u8bbe\u8ba1\uff0c\u6211\u4eec\u63d0\u51fa\u4e86\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u5de6\u4fa7\u7684\u884c\u53f7\u7d22\u5f15\u8bbe\u7f6e\u4e3a\uff0c\u53f3\u4fa7\u7684\u5c0f\u65b9\u5757\u8bbe\u7f6e\u4e3a\uff0c\u800c\u5b83\u4eec\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u4e3a\u76f8\u5bf9\u5b9a\u4f4d\u5e76\u9690\u85cf\u6ea2\u51fa\u3002<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\/\/ index.js\nimport react from \"react\";\nimport reactdom from \"react-dom\";\nimport \".\/styles.css\";\n\nfunction app() {\n  const itemdata = new array(500).fill(0);\n  const indexdata = new array(20).fill(0);\n\n  return (\n    &lt;div classname=\"app\"&gt;\n      &lt;div classname=\"left-box\"&gt;\n        {indexdata.map((item, index) =&gt; (\n          &lt;div\n            key={index}\n            style={{\n              fontsize: \"9px\",\n              width: \"19px\",\n              height: \"20px\",\n              margin: \"2px\",\n            }}\n          &gt;\n            {index}\n          &lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n      &lt;div classname=\"right-box\"&gt;\n        {itemdata.map((item, index) =&gt; (\n          &lt;div\n            key={index}\n            style={{\n              display: \"inline-block\",\n              width: \"9px\",\n              height: \"9px\",\n              margin: \"2px\",\n              backgroundcolor: item.selected ? \"green\" : \"lightgreen\",\n            }}\n          &gt;&lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n    &lt;\/div&gt;\n  );\n}\n\nconst rootelement = document.getelementbyid(\"root\");\nreactdom.render(&lt;app \/&gt;, rootelement);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>\/\/ styles.css\n.App {\n  font-family: sans-serif;\n  text-align: center;\n  overflow: hidden;\n  position: relative;\n}\n\n.left-box {\n  position: absolute;\n  left: 0;\n  top: 0;\n\n  width: 19px;\n  overflow: hidden;\n}\n\n.right-box {\n  margin-left: 19px;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528React\u7ec4\u4ef6\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u884c\u53f7\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>\u7ed9\u5bb9\u5668\u6dfb\u52a0\u884c\u53f7 \u5728react\u7ec4\u4ef6\u4e2d\u521b\u5efa\u5f88\u591a\u5c0f\u65b9\u683c\u540e\uff0c\u7531\u4e8e\u9879\u76ee\u7684\u9700\u8981\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u7ed9\u5bb9\u5668\u6dfb\u52a0\u884c\u53f7\u3002 \u5bf9\u4e8e\u5982\u4f55\u8bbe\u8ba1\uff0c\u6211\u4eec\u63d0\u51fa\u4e86\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002 \u5de6\u4fa7\u7684\u884c\u53f7\u7d22\u5f15\u8bbe\u7f6e\u4e3a\uff0c\u53f3\u4fa7\u7684\u5c0f\u65b9\u5757\u8bbe\u7f6e\u4e3a\uff0c\u800c\u5b83\u4eec\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u4e3a\u76f8\u5bf9\u5b9a\u4f4d\u5e76\u9690\u85cf\u6ea2\u51fa\u3002 \u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a \/\/ index.js import react from &#8220;react&#8221;; import reactdom from &#8220;react-dom&#8221;; import &#8220;.\/styles.css&#8221;; function app() { const itemdata = new array(500).fill(0); const indexdata = new array(20).fill(0); return ( &lt;div classname=&#8221;app&#8221;&gt; &lt;div classname=&#8221;left-box&#8221;&gt; {indexdata.map((item, index) =&gt; ( &lt;div key={index} style={{ fontsize: &#8220;9px&#8221;, width: &#8220;19px&#8221;, height: &#8220;20px&#8221;, margin: &#8220;2px&#8221;, }} &gt; {index} &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-27650","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27650","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=27650"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27650\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}