{"id":27545,"date":"2024-11-24T14:51:11","date_gmt":"2024-11-24T06:51:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27545\/"},"modified":"2024-11-24T14:51:11","modified_gmt":"2024-11-24T06:51:11","slug":"react-%e4%b8%ad%e5%a6%82%e4%bd%95%e8%ae%a9%e8%b6%85%e5%87%ba-div-%e7%95%8c%e9%9d%a2%e5%90%8e%e5%90%af%e7%94%a8%e5%8f%af%e4%b8%8a%e4%b8%8b%e6%8b%96%e5%8a%a8%e6%bb%91%e6%9d%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27545\/","title":{"rendered":"React \u4e2d\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173128826767513.jpg\" class=\"aligncenter\" title=\"React \u4e2d\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\uff1f\u63d2\u56fe\" alt=\"React \u4e2d\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>react \u4e2d\u8d85\u51fa div \u754c\u9762\u5e76\u542f\u7528\u6ed1\u6761\u6eda\u52a8<\/strong><\/p>\n<p>\u5728 react \u4e2d\uff0c\u5f53\u67d0\u4e2a\u5143\u7d20\u7684\u5185\u5bb9\u8d85\u51fa\u7236\u5143\u7d20\u7684\u8fb9\u6846\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528  \u5c5e\u6027\u6765\u63a7\u5236\u5b83\u7684\u663e\u793a\u65b9\u5f0f\u3002\u4e0b\u9762\u662f\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\uff1a<\/p>\n<p>\u5728 subcontner \u7ec4\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6837\u5f0f\uff1a<\/p>\n<pre>overflow: 'auto'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u66f4\u65b0\u540e\u7684\u4ee3\u7801\u5982\u4e0b\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>\u901a\u8fc7\u6dfb\u52a0 overflow: &#8216;auto&#8217;\uff0c\u5982\u679c\u5b50\u5143\u7d20\u8d85\u51fa\u7236\u5143\u7d20\uff0c\u5c06\u663e\u793a\u5782\u76f4\u6eda\u52a8\u6761\uff0c\u5141\u8bb8\u7528\u6237\u6eda\u52a8\u67e5\u770b\u5269\u4f59\u5185\u5bb9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fReact \u4e2d\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\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>react \u4e2d\u8d85\u51fa div \u754c\u9762\u5e76\u542f\u7528\u6ed1\u6761\u6eda\u52a8 \u5728 react \u4e2d\uff0c\u5f53\u67d0\u4e2a\u5143\u7d20\u7684\u5185\u5bb9\u8d85\u51fa\u7236\u5143\u7d20\u7684\u8fb9\u6846\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 \u5c5e\u6027\u6765\u63a7\u5236\u5b83\u7684\u663e\u793a\u65b9\u5f0f\u3002\u4e0b\u9762\u662f\u5982\u4f55\u8ba9\u8d85\u51fa div \u754c\u9762\u540e\u542f\u7528\u53ef\u4e0a\u4e0b\u62d6\u52a8\u6ed1\u6761\uff1a \u5728 subcontner \u7ec4\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6837\u5f0f\uff1a overflow: &#8216;auto&#8217; \u767b\u5f55\u540e\u590d\u5236 \u66f4\u65b0\u540e\u7684\u4ee3\u7801\u5982\u4e0b\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){ [&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-27545","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27545","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=27545"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27545\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}