{"id":52566,"date":"2024-12-03T13:30:43","date_gmt":"2024-12-03T05:30:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52566\/"},"modified":"2024-12-03T13:30:43","modified_gmt":"2024-12-03T05:30:43","slug":"react%e7%bb%84%e4%bb%b6%e5%86%85%e5%ae%b9%e8%b6%85%e5%87%badiv%e8%be%b9%e7%95%8c%e5%a6%82%e4%bd%95%e6%98%be%e7%a4%ba%e6%bb%9a%e5%8a%a8%e6%9d%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52566\/","title":{"rendered":"React\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>React\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aReact\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732181990673effe68b421.jpg\" class=\"aligncenter\" title=\"React\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f\u63d2\u56fe\" alt=\"React\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u7684\u5185\u5bb9\u663e\u793a\u6eda\u52a8\u6761<\/strong><\/p>\n<p>\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u5b50\u7ec4\u4ef6\uff1a<\/p>\n<pre>import react from 'react'\n\nexport type itemtype = {\n    type: &amp;quot;property&amp;quot; | &amp;quot;method&amp;quot;,\n    value: string,\n    selected?: boolean    \n}\n\nexport type subcontainerprops = {\n    height?: number,\n    title: string,\n    data: itemtype[], \/\/ \u8fd9\u4e2a\u662fitems\n}\n\nexport default function subcontainer (props: subcontainerprops){ \n\n   \n\n    return (\n        &lt;div style={{borderradius: '8px',  border: '2px dashed #333', height: props.height}}&gt;\n            &lt;div style={{textalign: 'left'}}&gt;\n                &lt;label&gt;{props.title}&lt;\/label&gt;\n            &lt;\/div&gt;\n            &lt;div&gt;\n                {props.data.map((item, index) =&gt; (\n                    &lt;div \n                        key={`${index}-${item.type}-${item.value} `} \n                        style={{ \n                            float: 'left', \n                            display: 'inline-block', \n                            borderradius: '6px', \n                            border: '2px solid #000', \n                            margin: '8px', \n                            padding:'4px',\n                            backgroundcolor: item.selected ? '#39fe40': '' \n                        }}\n                        \n                    &gt;{item.value}&lt;\/div&gt;\n                ))}\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    )\n}<\/pre>\n<p>\u4f46\u5f53 props.data \u4e2d\u7684\u5185\u5bb9\u8f83\u591a\u65f6\uff0c\u4f1a\u8d85\u51fa\u754c\u9762\u7684\u663e\u793a\u8303\u56f4\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u5728\u8be5 div \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u6837\u5f0f\uff1a<\/p>\n<pre>overflow: 'auto'<\/pre>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>return (\n        &lt;div style={{borderRadius: '8px',  border: '2px dashed #333', height: props.height, overflow: 'auto'}}&gt;\n            &lt;div style={{textAlign: 'left'}}&gt;\n                &lt;label&gt;{props.title}&lt;\/label&gt;\n            &lt;\/div&gt;\n            &lt;div&gt;\n                {props.data.map((item, index) =&gt; (\n                    &lt;div \n                        key={`${index}-${item.type}-${item.value} `} \n                        style={{ \n                            float: 'left', \n                            display: 'inline-block', \n                            borderRadius: '6px', \n                            border: '2px solid #000', \n                            margin: '8px', \n                            padding:'4px',\n                            backgroundColor: item.selected ? '#39fe40': '' \n                        }}\n                        \n                    &gt;{item.value}&lt;\/div&gt;\n                ))}\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    )<\/pre>\n<p>\u8fd9\u6837\uff0c\u5f53\u5185\u5bb9\u8d85\u51fa\u754c\u9762\u8303\u56f4\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0\u6eda\u52a8\u6761\uff0c\u4ee5\u4fbf\u4e0a\u4e0b\u62d6\u52a8\u8fdb\u884c\u67e5\u770b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   CSS \u4e2d\u884c\u5185\u5143\u7d20\u6362\u884c\u540e\u9996\u5b57\u7b26\u6837\u5f0f\u4e22\u5931\u600e\u4e48\u529e\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>React\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aReact\u7ec4\u4ef6\u5185\u5bb9\u8d85\u51fadiv\u8fb9\u754c\u5982\u4f55\u663e\u793a\u6eda\u52a8\u6761\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b \u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u7684\u5185\u5bb9\u663e\u793a\u6eda\u52a8\u6761 \u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u5b50\u7ec4\u4ef6\uff1a import react from &#8216;react&#8217; export type itemtype = { type: &amp;quot;property&amp;quot; | &amp;quot;method&amp;quot;, value: string, selected?: boolean } export type subcontainerprops = { height?: number, title: string, data: itemtype[], \/\/ \u8fd9\u4e2a\u662fitems } export default function subcontainer (props: subcontainerprops){ return ( &lt;div style={{borderradius: &#8216;8px&#8217;, border: &#8216;2px dashed #333&#8217;, height: props.height}}&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-52566","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52566","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=52566"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52566\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}