{"id":26164,"date":"2024-11-24T10:26:35","date_gmt":"2024-11-24T02:26:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26164\/"},"modified":"2024-11-24T10:26:35","modified_gmt":"2024-11-24T02:26:35","slug":"%e5%9c%a8%e7%bb%84%e4%bb%b6%e4%b8%ad%e4%bd%bf%e7%94%a8-global-%e4%bf%ae%e6%94%b9-antd-%e5%85%a8%e5%b1%80%e6%a0%b7%e5%bc%8f%e4%b8%ba%e4%bd%95%e5%a4%b1%e6%95%88%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26164\/","title":{"rendered":"\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u4e3a\u4f55\u5931\u6548\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085175216109.jpg\" class=\"aligncenter\" title=\"\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u4e3a\u4f55\u5931\u6548\uff1f\u63d2\u56fe\" alt=\"\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u4e3a\u4f55\u5931\u6548\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u6837\u5f0f\u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u7684\u56f0\u60d1<\/strong><\/p>\n<p>\u5728 Antd \u4e2d\uff0c:global \u7528\u4e8e\u5728\u7ec4\u4ef6\u5185\u90e8\u8986\u76d6\u5168\u5c40\u6837\u5f0f\u3002\u4f46\u662f\uff0c\u5982\u679c\u5c1d\u8bd5\u4f7f\u7528\u6b64\u65b9\u6cd5\u65f6\u672a\u751f\u6548\uff0c\u4ee5\u4e0b\u539f\u56e0\u53ef\u80fd\u662f\u7f6a\u9b41\u7978\u9996\uff1a<\/p>\n<p><strong>\u5bfc\u5165\u65b9\u5f0f\u4e0d\u6b63\u786e<\/strong><\/p>\n<p>:global \u6837\u5f0f\u9700\u8981\u663e\u5f0f\u5730\u5bfc\u5165\u3002\u5c06\u539f\u5148\u7684\u5bfc\u5165\u65b9\u5f0f import &#8216;.\/index.module.&#8217; \u6539\u4e3a import MyStyles from &#8216;.\/index.module.css&#8217;.<\/p>\n<p><strong>\u9009\u62e9\u5668\u9519\u8bef<\/strong><\/p>\n<p>\u9009\u62e9\u7684\u5143\u7d20\u5fc5\u987b\u662f\u5168\u5c40\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7ec4\u4ef6\u7684\u5b50\u5143\u7d20\u3002\u6b63\u786e\u7684\u9009\u62e9\u5668\u5e94\u8be5\u4e3a .myButton:global(.ant-btn-primary) \uff0c\u800c\u4e0d\u662f .myButton :global(.ant-btn-primary) \u3002<\/p>\n<p><strong>\u5176\u4ed6\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86\u4f7f\u7528 CSS Modules \u5916\uff0c\u8fd8\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u539f\u751f\u7684 CSS \u6587\u4ef6\uff08.css\uff09\uff0c\u800c\u4e0d\u662f\u6a21\u5757\u5316 CSS\uff08.module.css\uff09\u3002<\/li>\n<li>\u5728 CSS \u6587\u4ef6\u4e2d\uff0c\u4ee5\u6b63\u5e38\u65b9\u5f0f\u7f16\u5199\u9009\u62e9\u5668\uff0c\u4e0d\u9700\u8981 :global \u5173\u952e\u5b57\uff0c\u4f8b\u5982 .myButton.ant-btn-primary { &#8230; } \u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u4fee\u590d\u65b9\u6cd5\u53ef\u4ee5\u786e\u4fdd\u5728\u7ec4\u4ef6\u4e2d\u6210\u529f\u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u4e3a\u4f55\u5931\u6548\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\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u6837\u5f0f\u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u7684\u56f0\u60d1 \u5728 Antd \u4e2d\uff0c:global \u7528\u4e8e\u5728\u7ec4\u4ef6\u5185\u90e8\u8986\u76d6\u5168\u5c40\u6837\u5f0f\u3002\u4f46\u662f\uff0c\u5982\u679c\u5c1d\u8bd5\u4f7f\u7528\u6b64\u65b9\u6cd5\u65f6\u672a\u751f\u6548\uff0c\u4ee5\u4e0b\u539f\u56e0\u53ef\u80fd\u662f\u7f6a\u9b41\u7978\u9996\uff1a \u5bfc\u5165\u65b9\u5f0f\u4e0d\u6b63\u786e :global \u6837\u5f0f\u9700\u8981\u663e\u5f0f\u5730\u5bfc\u5165\u3002\u5c06\u539f\u5148\u7684\u5bfc\u5165\u65b9\u5f0f import &#8216;.\/index.module.&#8217; \u6539\u4e3a import MyStyles from &#8216;.\/index.module.css&#8217;. \u9009\u62e9\u5668\u9519\u8bef \u9009\u62e9\u7684\u5143\u7d20\u5fc5\u987b\u662f\u5168\u5c40\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7ec4\u4ef6\u7684\u5b50\u5143\u7d20\u3002\u6b63\u786e\u7684\u9009\u62e9\u5668\u5e94\u8be5\u4e3a .myButton:global(.ant-btn-primary) \uff0c\u800c\u4e0d\u662f .myButton :global(.ant-btn-primary) \u3002 \u5176\u4ed6\u89e3\u51b3\u65b9\u6cd5 \u9664\u4e86\u4f7f\u7528 CSS Modules \u5916\uff0c\u8fd8\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528\u539f\u751f\u7684 CSS \u6587\u4ef6\uff08.css\uff09\uff0c\u800c\u4e0d\u662f\u6a21\u5757\u5316 CSS\uff08.module.css\uff09\u3002 \u5728 CSS \u6587\u4ef6\u4e2d\uff0c\u4ee5\u6b63\u5e38\u65b9\u5f0f\u7f16\u5199\u9009\u62e9\u5668\uff0c\u4e0d\u9700\u8981 :global \u5173\u952e\u5b57\uff0c\u4f8b\u5982 .myButton.ant-btn-primary { &#8230; } \u3002 \u8fd9\u4e9b\u4fee\u590d\u65b9\u6cd5\u53ef\u4ee5\u786e\u4fdd\u5728\u7ec4\u4ef6\u4e2d\u6210\u529f\u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u3002 \u4ee5\u4e0a\u5c31\u662f\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 :global \u4fee\u6539 Antd \u5168\u5c40\u6837\u5f0f\u4e3a\u4f55\u5931\u6548\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26164","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26164","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=26164"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26164\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}