{"id":2003,"date":"2024-11-10T15:00:26","date_gmt":"2024-11-10T07:00:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2003\/"},"modified":"2024-11-10T15:00:26","modified_gmt":"2024-11-10T07:00:26","slug":"mui-stack%ef%bc%9a%e6%8e%8c%e6%8f%a1-react-%e4%b8%ad%e7%9a%84%e4%b8%80%e7%bb%b4%e5%b8%83%e5%b1%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2003\/","title":{"rendered":"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40"},"content":{"rendered":"<h3> \u4ecb\u7ecd <\/h3>\n<p>\u521b\u5efa\u65e0\u7f1d\u7684\u4e00\u7ef4\u5e03\u5c40\u5728 web \u5f00\u53d1\u4e2d\u901a\u5e38\u5177\u6709\u6311\u6218\u6027\uff0c\u4f46 <strong>mui stack<\/strong> \u4f7f\u5176\u53d8\u5f97\u7b80\u5355\u3002 mui \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 react \u7ec4\u4ef6\u5e93\uff0c\u5b83\u63d0\u4f9b stack \u7ec4\u4ef6\u4f5c\u4e3a\u7ba1\u7406\u5782\u76f4\u548c\u6c34\u5e73\u7684\u6709\u6548\u5de5\u5177\uff0c\u800c\u65e0\u9700\u6df1\u5165\u7814\u7a76 flexbox \u6216\u81ea\u5b9a\u4e49 \u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u4e86\u89e3 mui stack \u4ece\u8bbe\u7f6e\u5230\u5b9e\u9645\u4f7f\u7528\u7684\u57fa\u672c\u77e5\u8bc6\uff0c\u4ee5\u589e\u5f3a\u60a8\u5728 react \u4e2d\u7684\u5e03\u5c40\u6784\u5efa\u4f53\u9a8c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062808688591.jpg\" class=\"aligncenter\" title=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe\" alt=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe\" \/><\/p>\n<h3> mui \u5806\u6808\u5165\u95e8 <\/h3>\n<p>\u8981\u5f00\u59cb\u4f7f\u7528 mui stack \u6784\u5efa\u5e03\u5c40\uff0c\u8bf7\u786e\u4fdd\u5b89\u88c5\u4e86\u5fc5\u8981\u7684 mui \u8f6f\u4ef6\u5305\u3002 mui \u7684 stack \u7ec4\u4ef6\u4f9d\u8d56\u4e8e\u4e09\u4e2a\u4e3b\u8981\u5305\uff1a<\/p>\n<ul>\n<li> <strong>@mui\/material<\/strong>\uff1a\u8fd9\u662f\u5305\u542b\u6240\u6709 mui \u7ec4\u4ef6\u7684\u6838\u5fc3\u5305\uff0c\u5305\u62ec stack\u3002<\/li>\n<li> <strong>@emotion\/react<\/strong> \u548c <strong>@emotion\/styled<\/strong>\uff1amui \u9ed8\u8ba4\u4f7f\u7528 emotion \u8fdb\u884c\u6837\u5f0f\u8bbe\u7f6e\uff0c\u8fd9\u4e9b\u5305\u53ef\u4ee5\u65e0\u7f1d\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u6837\u5f0f\u3002<\/li>\n<\/ul>\n<h4> \u5b89\u88c5 <\/h4>\n<p>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u8f6f\u4ef6\u5305\uff1a<\/p>\n<pre># using npm\nnpm install @mui\/material @emotion\/react @emotion\/styled\n\n# using yarn\nyarn add @mui\/material @emotion\/react @emotion\/styled\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u6b65\u9aa4\u5c06\u4e3a\u60a8\u5b9e\u73b0\u5177\u6709\u6240\u6709\u5fc5\u8981\u4f9d\u8d56\u9879\u7684 mui stack \u505a\u597d\u51c6\u5907\u3002 <em>\uff08\u5305\u62ec\u7ec8\u7aef\u5b89\u88c5\u8fc7\u7a0b\u7684\u5c4f\u5e55\u622a\u56fe\uff0c\u4ee5\u4f9b\u5feb\u901f\u89c6\u89c9\u53c2\u8003\u3002\uff09<\/em><\/p>\n<h3> mui \u5806\u6808\u7684\u57fa\u672c\u8bbe\u7f6e <\/h3>\n<p>\u5b89\u88c5\u5b8c\u8f6f\u4ef6\u5305\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u5c06 stack \u5408\u5e76\u5230\u60a8\u7684\u9879\u76ee\u4e2d\u4e86\u3002\u8ba9\u6211\u4eec\u5b8c\u6210\u521d\u59cb\u8bbe\u7f6e\uff1a<\/p>\n<h4> \u5bfc\u5165\u548c\u4f7f\u7528\u5806\u6808 <\/h4>\n<p>\u9996\u5148\uff0c\u5728 react \u7ec4\u4ef6\u6587\u4ef6\u4e2d\u5bfc\u5165 stack \u7ec4\u4ef6\uff1a<\/p>\n<pre>import stack from '@mui\/material\/stack';\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u914d\u7f6e\u5806\u53e0\u65b9\u5411 <\/h4>\n<p>\u65b9\u5411\u5c5e\u6027\u662f mui stack \u7684\u6838\u5fc3\uff0c\u53ef\u8ba9\u60a8\u8f7b\u677e\u8bbe\u7f6e\u6c34\u5e73\u6216\u5782\u76f4\u6392\u5217\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cstack \u5c06\u5176\u5b50\u5143\u7d20\u6392\u5217\u5728\u5782\u76f4\u5217\u4e2d\uff0c\u8fd9\u975e\u5e38\u9002\u5408\u4ece\u4e0a\u5230\u4e0b\u5806\u53e0\u5143\u7d20\u3002\u5bf9\u4e8e\u6c34\u5e73\u5e03\u5c40\uff0c\u8bf7\u5c06\u65b9\u5411\u5207\u6362\u4e3a\u201c\u884c\u201d\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre>import react from 'react';\nimport stack from '@mui\/material\/stack';\nimport typography from '@mui\/material\/typography';\n\nfunction app() {\n  return (\n    &lt;stack direction=\"row\" spacing={2}&gt;\n      &lt;typography variant=\"body1\"&gt;first item&lt;\/typography&gt;\n      &lt;typography variant=\"body1\"&gt;second item&lt;\/typography&gt;\n      &lt;typography variant=\"body1\"&gt;third item&lt;\/typography&gt;\n    &lt;\/stack&gt;\n  );\n}\n\nexport default app;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u4ee3\u7801\u4e2d\uff0cdirection=&#8221;row&#8221; \u6c34\u5e73\u5e76\u6392\u6392\u5217\u9879\u76ee\uff0c\u6bcf\u4e2a\u9879\u76ee\u4e4b\u95f4\u6709\u95f4\u8ddd\u3002\u6b64\u8bbe\u7f6e\u6709\u52a9\u4e8e\u521b\u5efa\u83dc\u5355\u680f\u3001\u9879\u76ee\u5217\u8868\u6216\u4efb\u4f55\u60f3\u8981\u4ee5\u884c\u683c\u5f0f\u663e\u793a\u7684\u5143\u7d20\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062808640226.jpg\" class=\"aligncenter\" title=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe1\" alt=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe1\" \/><\/p>\n<p>\u6709\u4e86\u8fd9\u4e2a\u57fa\u7840\uff0cmui stack \u5c31\u53ef\u4ee5\u7b80\u5316\u60a8\u7684\u5e03\u5c40\u6784\u5efa\u4f53\u9a8c\u3002\u8bf7\u7ee7\u7eed\u5173\u6ce8\u6211\u4eec\u6df1\u5165\u63a2\u8ba8\u914d\u7f6e\u3001\u95f4\u8ddd\u548c\u54cd\u5e94\u5f0f\u5e03\u5c40\u3002 <\/p>\n<h3> \u914d\u7f6e\u95f4\u8ddd\u548c\u54cd\u5e94\u80fd\u529b <\/h3>\n<p>\u6709\u6548\u7684\u95f4\u8ddd\u662f\u521b\u5efa\u5177\u6709\u89c6\u89c9\u5438\u5f15\u529b\u7684\u5e03\u5c40\u7684\u5173\u952e\uff0c\u800c mui stack \u53ef\u4ee5\u8f7b\u677e\u8c03\u6574\u5143\u7d20\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002\u4f7f\u7528\u95f4\u8ddd\u5c5e\u6027\uff0c\u60a8\u53ef\u4ee5\u5b9a\u4e49\u5b50\u5143\u7d20\u4e4b\u95f4\u4e00\u81f4\u7684\u95f4\u9699\uff0c\u53ef\u4ee5\u662f\u56fa\u5b9a\u503c\uff0c\u4e5f\u53ef\u4ee5\u54cd\u5e94\u5c4f\u5e55\u5c3a\u5bf8\u3002<\/p>\n<h4> \u95f4\u8ddd <\/h4>\n<p>\u8981\u8bbe\u7f6e\u56fa\u5b9a\u95f4\u8ddd\uff0c\u53ea\u9700\u4f7f\u7528\u5e26\u6709\u6570\u503c\u7684\u95f4\u8ddd\u5c5e\u6027\u5373\u53ef\u3002\u4f8b\u5982\uff0cspacing={2} \u5c06\u5728\u6240\u6709\u5b50\u9879\u4e4b\u95f4\u6dfb\u52a0\u7edf\u4e00\u7684\u95f4\u9699\uff1a<\/p>\n<pre>&lt;stack direction=\"row\" spacing={2}&gt;\n  &lt;typography variant=\"body1\"&gt;item 1&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 2&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 3&lt;\/typography&gt;\n&lt;\/stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u91cc\uff0cstack \u4e2d\u7684\u6bcf\u4e2a\u9879\u76ee\u4e4b\u95f4\u90fd\u6709\u56fa\u5b9a\u7684\u95f4\u9699\uff0c\u4ece\u800c\u521b\u5efa\u5747\u5300\u95f4\u9694\u3001\u5e72\u51c0\u7684\u5e03\u5c40\u3002<\/p>\n<h4> \u54cd\u5e94\u5f0f\u95f4\u8ddd <\/h4>\n<p>mui stack \u8fd8\u5141\u8bb8\u901a\u8fc7\u5c06\u5bf9\u8c61\u4f20\u9012\u7ed9\u95f4\u8ddd\u5c5e\u6027\u6765\u5b9e\u73b0\u54cd\u5e94\u5f0f\u95f4\u8ddd\u3002\u8fd9\u53ef\u4ee5\u6839\u636e\u5c4f\u5e55\u5c3a\u5bf8\u65ad\u70b9\uff08\u4f8b\u5982\uff0cxs\u3001sm\u3001md\uff09\u542f\u7528\u4e0d\u540c\u7684\u95f4\u8ddd\u503c\uff1a<\/p>\n<pre>&lt;stack direction=\"row\" spacing={{ xs: 1, sm: 2, md: 3 }}&gt;\n  &lt;typography variant=\"body1\"&gt;item 1&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 2&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 3&lt;\/typography&gt;\n&lt;\/stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u95f4\u8ddd\u5728\u8f83\u5c0f\u7684\u5c4f\u5e55\u4e0a\u4f1a\u66f4\u7a84\uff0c\u5728\u8f83\u5927\u7684\u5c4f\u5e55\u4e0a\u4f1a\u66f4\u5bbd\uff0c\u81ea\u52a8\u8c03\u6574\u4ee5\u83b7\u5f97\u6700\u4f73\u7684\u53ef\u8bfb\u6027\u3002 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062808659289.jpg\" class=\"aligncenter\" title=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe2\" alt=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe2\" \/><\/p>\n<p>\u53e6\u4e00\u4e2a\u6709\u7528\u7684\u529f\u80fd\u662f stack \u80fd\u591f\u54cd\u5e94\u5f0f\u8c03\u6574\u65b9\u5411\uff0c\u5e2e\u52a9\u60a8\u7684\u5e03\u5c40\u9002\u5e94\u5404\u79cd\u5c4f\u5e55\u5c3a\u5bf8\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6edirection={{ xs: &#8220;column&#8221;, sm: &#8220;row&#8221; }}:<br \/>\u4e3a\u4e0d\u540c\u7684\u65ad\u70b9\u6307\u5b9a\u4e0d\u540c\u7684\u65b9\u5411 <\/p>\n<pre>&lt;stack direction={{ xs: \"column\", sm: \"row\" }} spacing={2}&gt;\n  &lt;typography variant=\"body1\"&gt;item 1&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 2&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 3&lt;\/typography&gt;\n&lt;\/stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u8bbe\u7f6e\u4e2d\uff0c\u9879\u76ee\u5728\u8d85\u5c0f\u5c4f\u5e55\uff08\u4f8b\u5982\u624b\u673a\uff09\u4e0a\u6309\u5217\u6392\u5217\uff0c\u5e76\u5728\u5c0f\u5c4f\u5e55\uff08\u4f8b\u5982\u5e73\u677f\u7535\u8111\uff09\u548c\u66f4\u5927\u5c4f\u5e55\u4e0a\u5207\u6362\u4e3a\u884c\u5e03\u5c40\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062808637450.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe3\" alt=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe3\" \/><\/p>\n<h3> \u589e\u5f3a\u7684\u5e03\u5c40\u5b9a\u5236 <\/h3>\n<p>mui stack \u63d0\u4f9b\u4e86\u591a\u4e2a\u81ea\u5b9a\u4e49\u9009\u9879\uff0c\u7528\u4e8e\u6784\u5efa\u66f4\u590d\u6742\u3001\u66f4\u7cbe\u7f8e\u7684\u5e03\u5c40\u3002\u8ba9\u6211\u4eec\u63a2\u7d22\u5982\u4f55\u4f7f\u7528\u5206\u9694\u7ebf\u548c\u5bf9\u9f50\u8bbe\u7f6e\u6765\u8fdb\u4e00\u6b65\u4f18\u5316\u5e03\u5c40\u3002<\/p>\n<h4> \u6dfb\u52a0\u5206\u9694\u7ebf <\/h4>\n<p>divider \u5c5e\u6027\u5141\u8bb8\u60a8\u5728 stack \u9879\u76ee\u4e4b\u95f4\u63d2\u5165\u89c6\u89c9\u5206\u9694\u7b26\u3002\u8fd9\u5bf9\u4e8e\u6e05\u6670\u5206\u9694\u5217\u8868\u3001\u5bfc\u822a\u83dc\u5355\u6216\u6309\u94ae\u7ec4\u4e2d\u7684\u5143\u7d20\u7279\u522b\u6709\u7528\u3002<\/p>\n<pre>import divider from '@mui\/material\/divider';\n\n&lt;stack direction=\"row\" divider={&lt;divider orientation=\"vertical\" flexitem \/&gt;} spacing={2}&gt;\n  &lt;typography variant=\"body1\"&gt;item 1&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 2&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 3&lt;\/typography&gt;\n&lt;\/stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u884c\u5e03\u5c40\u4e2d\u7684\u6bcf\u4e2a\u9879\u76ee\u4e4b\u95f4\u653e\u7f6e\u4e86\u4e00\u4e2a\u5782\u76f4\u5206\u9694\u7ebf\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u53ef\u8bfb\u6027\u548c\u7ed3\u6784\u3002\u5982\u679c\u5806\u53e0\u65b9\u5411\u8bbe\u7f6e\u4e3a\u5217\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5c06\u65b9\u5411\u8bbe\u7f6e\u4e3a\u6c34\u5e73\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062808725690.jpg\" class=\"aligncenter\" title=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe4\" alt=\"MUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u63d2\u56fe4\" \/><\/p>\n<h4> \u7406\u7531\u548c\u5bf9\u9f50 <\/h4>\n<p>\u4e3a\u4e86\u7cbe\u786e\u5b9a\u4f4d stack \u9879\u76ee\uff0cmui stack \u652f\u6301 justifycontent \u548calignitems \u5c5e\u6027\uff0c\u5b83\u4eec\u5206\u522b\u63a7\u5236\u6cbf\u4e3b\u8f74\u548c\u4ea4\u53c9\u8f74\u7684\u5bf9\u9f50\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li> <strong>justifycontent<\/strong>\uff1a\u6cbf\u4e3b\u8f74\u5bf9\u9f50\u9879\u76ee\uff08\u5982\u679c\u65b9\u5411=\u201c\u884c\u201d\u5219\u6c34\u5e73\u5bf9\u9f50\uff1b\u5982\u679c\u65b9\u5411=\u201c\u5217\u201d\u5219\u5782\u76f4\uff09\u3002<\/li>\n<li> <strong>alignitems<\/strong>\uff1a\u6cbf\u4ea4\u53c9\u8f74\u5bf9\u9f50\u9879\u76ee\uff08\u5982\u679c\u65b9\u5411=\u201c\u884c\u201d\u5219\u5782\u76f4\uff1b\u5982\u679c\u65b9\u5411=\u201c\u5217\u201d\u5219\u6c34\u5e73\uff09\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;stack\n  direction=\"row\"\n  spacing={2}\n  justifycontent=\"center\"\n  alignitems=\"center\"\n&gt;\n  &lt;typography variant=\"body1\"&gt;item 1&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 2&lt;\/typography&gt;\n  &lt;typography variant=\"body1\"&gt;item 3&lt;\/typography&gt;\n&lt;\/stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u8bbe\u7f6e\u4e2d\uff0c justifycontent=&#8221;center&#8221; \u4f7f\u9879\u76ee\u6cbf\u4e3b\u8f74\u5c45\u4e2d\uff0c\u800calignitems=&#8221;center&#8221; \u4f7f\u5b83\u4eec\u6cbf\u6a2a\u8f74\u5c45\u4e2d\uff0c\u4ece\u800c\u5f62\u6210\u6574\u9f50\u5c45\u4e2d\u7684\u5e03\u5c40\u3002\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u60a8\u80fd\u591f\u521b\u5efa\u9002\u5e94\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u5e76\u4fdd\u6301\u89c6\u89c9\u548c\u8c10\u7684\u5e03\u5c40\u3002<\/p>\n<h3> \u4f7f\u7528\u7cfb\u7edf\u9053\u5177\u8fdb\u884c\u81ea\u5b9a\u4e49\u6837\u5f0f <\/h3>\n<p>mui stack \u652f\u6301<strong>\u7cfb\u7edf\u5c5e\u6027<\/strong>\uff0c\u5b83\u4eec\u662f\u65b9\u4fbf\u7684\u6837\u5f0f\u5c5e\u6027\uff0c\u5141\u8bb8\u60a8\u76f4\u63a5\u5728\u7ec4\u4ef6\u4e0a\u5e94\u7528\u8fb9\u8ddd\u3001\u586b\u5145\u548c\u5176\u4ed6\u4e0e\u5e03\u5c40\u76f8\u5173\u7684 css\u3002\u7cfb\u7edf prop \u6d88\u9664\u4e86\u5bf9\u989d\u5916 css \u6587\u4ef6\u7684\u9700\u6c42\uff0c\u4f7f\u60a8\u80fd\u591f\u7ba1\u7406\u7ec4\u4ef6\u5185\u7684\u6837\u5f0f\uff0c\u4fdd\u6301\u4ee3\u7801\u7ec4\u7ec7\u6709\u5e8f\u4e14\u9ad8\u6548\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5728 stack \u5468\u56f4\u6dfb\u52a0\u5185\u8fb9\u8ddd\u6216\u5728 stack \u4e0e\u5176\u4ed6\u5143\u7d20\u4e4b\u95f4\u6dfb\u52a0\u8fb9\u8ddd\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8bbe\u7f6e p\uff08\u5185\u8fb9\u8ddd\uff09\u6216 m\uff08\u8fb9\u8ddd\uff09\u5c5e\u6027\uff1a<\/p>\n<pre>&lt;Stack\n  direction=\"row\"\n  spacing={2}\n  p={2} \/\/ Adds padding inside the Stack\n  m={3} \/\/ Adds margin outside the Stack\n  sx={{ bgcolor: 'grey.100' }} \/\/ Optional background color for emphasis\n&gt;\n  &lt;Typography variant=\"body1\"&gt;Item 1&lt;\/Typography&gt;\n  &lt;Typography variant=\"body1\"&gt;Item 2&lt;\/Typography&gt;\n  &lt;Typography variant=\"body1\"&gt;Item 3&lt;\/Typography&gt;\n&lt;\/Stack&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cp={2} \u5728 stack \u5468\u56f4\u6dfb\u52a0\u5185\u90e8\u586b\u5145\uff0c\u800c m={3} \u5728 stack \u548c\u9875\u9762\u4e0a\u7684\u5176\u4ed6\u5143\u7d20\u4e4b\u95f4\u521b\u5efa\u5916\u90e8\u8fb9\u8ddd\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u901f\u8bb0\u7cfb\u7edf\u9053\u5177\u8fdb\u884c\u5404\u79cd\u8c03\u6574\uff0c\u5305\u62ec\u8fb9\u8ddd (m)\u3001\u586b\u5145 (p)\u3001\u5bbd\u5ea6 (width) \u548c\u9ad8\u5ea6 (height)\uff0c\u65e0\u9700\u989d\u5916\u7684 css \u4ee3\u7801\u5373\u53ef\u63d0\u4f9b\u91cd\u8981\u7684\u5e03\u5c40\u63a7\u5236\u3002<\/p>\n<h3> \u4e03\u3001\u7ed3\u8bba <\/h3>\n<p>mui stack \u662f\u4e00\u4e2a\u9ad8\u5ea6\u7075\u6d3b\u4e14\u9ad8\u6548\u7684\u7ec4\u4ef6\uff0c\u7528\u4e8e\u7ba1\u7406 react \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\u3002\u901a\u8fc7\u7b80\u5316\u5143\u7d20\u7684\u5bf9\u9f50\u3001\u95f4\u8ddd\u548c\u54cd\u5e94\u80fd\u529b\uff0cstack \u51cf\u5c11\u4e86\u5bf9\u81ea\u5b9a\u4e49 css \u7684\u9700\u6c42\u5e76\u52a0\u901f\u4e86\u5f00\u53d1\u8fc7\u7a0b\u3002 <\/p>\n<p>\u901a\u8fc7\u7cfb\u7edf\u5c5e\u6027\u63a7\u5236\u5e03\u5c40\u65b9\u5411\u3001\u95f4\u8ddd\u548c\u6837\u5f0f\u7684\u80fd\u529b\u4f7f mui stack \u6210\u4e3a\u4efb\u4f55\u91cd\u89c6\u5e72\u51c0\u4e14\u53ef\u7ef4\u62a4\u4ee3\u7801\u7684\u9879\u76ee\u7684\u5f3a\u5927\u8865\u5145\u3002\u65e0\u8bba\u60a8\u662f\u6784\u5efa\u7b80\u5355\u7684\u5bfc\u822a\u680f\u8fd8\u662f\u590d\u6742\u7684\u54cd\u5e94\u5f0f\u5e03\u5c40\uff0cmui stack \u90fd\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5316\u7684\u65b9\u5f0f\u6765\u6784\u5efa ui\u3002 <\/p>\n<p>\u968f\u610f\u63a2\u7d22\u5176\u4ed6 mui \u6587\u6863\uff0c\u4ee5\u89e3\u9501\u66f4\u591a\u81ea\u5b9a\u4e49\u9009\u9879\uff0c\u4f8b\u5982\u9ad8\u7ea7\u7cfb\u7edf\u9053\u5177\u3001\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u589e\u5f3a\u529f\u80fd\u4ee5\u200b\u200b\u53ca\u5c06 stack \u4e0e\u5176\u4ed6 mui \u7ec4\u4ef6\u96c6\u6210\u4ee5\u83b7\u5f97\u5168\u9762\u7684\u5e03\u5c40\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMUI Stack\uff1a\u638c\u63e1 React \u4e2d\u7684\u4e00\u7ef4\u5e03\u5c40\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>\u4ecb\u7ecd \u521b\u5efa\u65e0\u7f1d\u7684\u4e00\u7ef4\u5e03\u5c40\u5728 web \u5f00\u53d1\u4e2d\u901a\u5e38\u5177\u6709\u6311\u6218\u6027\uff0c\u4f46 mui stack \u4f7f\u5176\u53d8\u5f97\u7b80\u5355\u3002 mui \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 react \u7ec4\u4ef6\u5e93\uff0c\u5b83\u63d0\u4f9b stack \u7ec4\u4ef6\u4f5c\u4e3a\u7ba1\u7406\u5782\u76f4\u548c\u6c34\u5e73\u7684\u6709\u6548\u5de5\u5177\uff0c\u800c\u65e0\u9700\u6df1\u5165\u7814\u7a76 flexbox \u6216\u81ea\u5b9a\u4e49 \u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u4e86\u89e3 mui stack \u4ece\u8bbe\u7f6e\u5230\u5b9e\u9645\u4f7f\u7528\u7684\u57fa\u672c\u77e5\u8bc6\uff0c\u4ee5\u589e\u5f3a\u60a8\u5728 react \u4e2d\u7684\u5e03\u5c40\u6784\u5efa\u4f53\u9a8c\u3002 mui \u5806\u6808\u5165\u95e8 \u8981\u5f00\u59cb\u4f7f\u7528 mui stack \u6784\u5efa\u5e03\u5c40\uff0c\u8bf7\u786e\u4fdd\u5b89\u88c5\u4e86\u5fc5\u8981\u7684 mui \u8f6f\u4ef6\u5305\u3002 mui \u7684 stack \u7ec4\u4ef6\u4f9d\u8d56\u4e8e\u4e09\u4e2a\u4e3b\u8981\u5305\uff1a @mui\/material\uff1a\u8fd9\u662f\u5305\u542b\u6240\u6709 mui \u7ec4\u4ef6\u7684\u6838\u5fc3\u5305\uff0c\u5305\u62ec stack\u3002 @emotion\/react \u548c @emotion\/styled\uff1amui \u9ed8\u8ba4\u4f7f\u7528 emotion \u8fdb\u884c\u6837\u5f0f\u8bbe\u7f6e\uff0c\u8fd9\u4e9b\u5305\u53ef\u4ee5\u65e0\u7f1d\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u6837\u5f0f\u3002 \u5b89\u88c5 \u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u8f6f\u4ef6\u5305\uff1a # using npm npm install @mui\/material @emotion\/react @emotion\/styled # using [&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-2003","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2003","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=2003"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2003\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}