{"id":27521,"date":"2024-11-24T08:08:03","date_gmt":"2024-11-24T00:08:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27521\/"},"modified":"2024-11-24T08:08:03","modified_gmt":"2024-11-24T00:08:03","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-react-%e4%b8%ad%e5%ae%9e%e7%8e%b0%e5%8f%af%e6%bb%9a%e5%8a%a8%e7%9a%84%e8%b6%85%e5%87%ba%e5%ae%b9%e5%99%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27521\/","title":{"rendered":"\u5982\u4f55\u5728 React \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173128503232481.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 React \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 React \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 react \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668<\/strong><\/p>\n<p>\u5f53\u4f60\u6709\u4e00\u4e2a\u5b50\u7ec4\u4ef6\u5305\u542b\u5927\u91cf\u6570\u636e\u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u8d85\u51fa\u5bb9\u5668\u7684\u8fb9\u754c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u8ba9\u6ea2\u51fa\u7684\u5185\u5bb9\u5728\u4e00\u4e2a\u53ef\u6eda\u52a8\u7684\u6ed1\u6761\u4e2d\u5c55\u793a\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u4e0a\u4e0b\u62d6\u52a8\u67e5\u770b\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u901a\u8fc7\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u4e00\u884c  \u5c5e\u6027\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u6b65\u9aa4\uff1a<\/p>\n<pre>import React from 'react'\n\nexport type ItemType = {\n    type: \"property\" | \"method\",\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, 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    )\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>overflow \u5c5e\u6027\u7684\u201cauto\u201d\u503c\u5141\u8bb8\u5143\u7d20\u5728\u5176\u5185\u5bb9\u8d85\u51fa\u8fb9\u754c\u65f6\u81ea\u52a8\u521b\u5efa\u6eda\u52a8\u6761\u3002\u8fd9\u5c06\u4f7f\u4f60\u7684\u5b50\u7ec4\u4ef6\u7684\u5185\u5bb9\u5728\u8d85\u51fa\u5bb9\u5668\u65f6\u53ef\u6eda\u52a8\u67e5\u770b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 React \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668\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>\u5728 react \u4e2d\u5b9e\u73b0\u53ef\u6eda\u52a8\u7684\u8d85\u51fa\u5bb9\u5668 \u5f53\u4f60\u6709\u4e00\u4e2a\u5b50\u7ec4\u4ef6\u5305\u542b\u5927\u91cf\u6570\u636e\u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u8d85\u51fa\u5bb9\u5668\u7684\u8fb9\u754c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u8ba9\u6ea2\u51fa\u7684\u5185\u5bb9\u5728\u4e00\u4e2a\u53ef\u6eda\u52a8\u7684\u6ed1\u6761\u4e2d\u5c55\u793a\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u4e0a\u4e0b\u62d6\u52a8\u67e5\u770b\u3002 \u4ee5\u4e0b\u662f\u901a\u8fc7\u5728\u5bb9\u5668\u4e2d\u6dfb\u52a0\u4e00\u884c \u5c5e\u6027\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u6b65\u9aa4\uff1a import React from &#8216;react&#8217; export type ItemType = { type: &#8220;property&#8221; | &#8220;method&#8221;, 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, [&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-27521","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27521","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=27521"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27521\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}