{"id":2594,"date":"2024-11-10T12:43:53","date_gmt":"2024-11-10T04:43:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2594\/"},"modified":"2024-11-10T12:43:53","modified_gmt":"2024-11-10T04:43:53","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8-global-%e4%bf%ae%e6%94%b9-antd-%e6%a0%b7%e5%bc%8f%e6%97%a0%e6%95%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2594\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4f7f\u7528 :global \u4fee\u6539 Antd \u6837\u5f0f\u65e0\u6548\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173080818496268.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u4f7f\u7528 :global \u4fee\u6539 Antd \u6837\u5f0f\u65e0\u6548\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u4f7f\u7528 :global \u4fee\u6539 Antd \u6837\u5f0f\u65e0\u6548\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>:global \u4fee\u6539 antd \u6837\u5f0f\u4e3a\u4f55\u65e0\u6548<\/strong><\/p>\n<p>\u672c\u6587\u65e8\u5728\u5e2e\u52a9\u60a8\u89e3\u51b3\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528:global\u4fee\u6539 antd \u5168\u5c40\u6837\u5f0f\u672a\u751f\u6548\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u60a8\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528:global\u4fee\u6539 antd \u6309\u94ae\u6837\u5f0f\uff0c\u4f46\u6ca1\u6709\u751f\u6548\u3002\u5b8c\u6574\u4ee3\u7801\u53ef\u53c2\u8003 https:\/\/codesandbox.io\/s\/fk7jnl \u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>:global\u6837\u5f0f\u5e76\u975e\u50cf\u60a8\u5bfc\u5165\u7684\u90a3\u6837\u5bfc\u5165\u3002\u60a8\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>import mystyles from '.\/index.module.css'\n\n...\n\n&lt;button classname={mystyles.mybutton} type=\"primary\" shape=\"circle\"&gt;\u6309\u94ae&lt;\/button&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u5916\uff0c\u9009\u62e9\u5668\u4e5f\u7f16\u5199\u4e0d\u6b63\u786e\u3002\u6b63\u786e\u7684\u9009\u62e9\u5668\u5e94\u8be5\u662f\uff1a<\/p>\n<pre>.mybutton:global(.ant-btn-primary) {\n  \/* \u6ce8\u610f\u6ca1\u6709\u7a7a\u683c\uff0c\u4e24\u8005\u4e0d\u662f\u7236\u5b50\u5173\u7cfb *\/\n  background-color: red !important;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u66ff\u4ee3\u65b9\u6848<\/strong><\/p>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u4e0d\u7528  modules\uff0c\u800c\u662f\u5728.css\u6587\u4ef6\u4e2d\u7f16\u5199\u4ee5\u4e0b css\uff1a<\/p>\n<pre>.myButton.ant-btn-primary {\n  background-color: red !important;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5e76\u5728  \u7ec4\u4ef6\u4e2d\u5bfc\u5165.css\u6587\u4ef6\uff0c\u4f7f\u7528\u76f8\u540c\u7684classname\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 :global \u4fee\u6539 Antd \u6837\u5f0f\u65e0\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>:global \u4fee\u6539 antd \u6837\u5f0f\u4e3a\u4f55\u65e0\u6548 \u672c\u6587\u65e8\u5728\u5e2e\u52a9\u60a8\u89e3\u51b3\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528:global\u4fee\u6539 antd \u5168\u5c40\u6837\u5f0f\u672a\u751f\u6548\u7684\u95ee\u9898\u3002 \u95ee\u9898\u63cf\u8ff0 \u60a8\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528:global\u4fee\u6539 antd \u6309\u94ae\u6837\u5f0f\uff0c\u4f46\u6ca1\u6709\u751f\u6548\u3002\u5b8c\u6574\u4ee3\u7801\u53ef\u53c2\u8003 https:\/\/codesandbox.io\/s\/fk7jnl \u3002 \u89e3\u51b3\u65b9\u6848 :global\u6837\u5f0f\u5e76\u975e\u50cf\u60a8\u5bfc\u5165\u7684\u90a3\u6837\u5bfc\u5165\u3002\u60a8\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u4ee5\u4e0b\u5185\u5bb9\uff1a import mystyles from &#8216;.\/index.module.css&#8217; &#8230; &lt;button classname={mystyles.mybutton} type=&#8221;primary&#8221; shape=&#8221;circle&#8221;&gt;\u6309\u94ae&lt;\/button&gt; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u5916\uff0c\u9009\u62e9\u5668\u4e5f\u7f16\u5199\u4e0d\u6b63\u786e\u3002\u6b63\u786e\u7684\u9009\u62e9\u5668\u5e94\u8be5\u662f\uff1a .mybutton:global(.ant-btn-primary) { \/* \u6ce8\u610f\u6ca1\u6709\u7a7a\u683c\uff0c\u4e24\u8005\u4e0d\u662f\u7236\u5b50\u5173\u7cfb *\/ background-color: red !important; } \u767b\u5f55\u540e\u590d\u5236 \u66ff\u4ee3\u65b9\u6848 \u60a8\u8fd8\u53ef\u4ee5\u4e0d\u7528 modules\uff0c\u800c\u662f\u5728.css\u6587\u4ef6\u4e2d\u7f16\u5199\u4ee5\u4e0b css\uff1a .myButton.ant-btn-primary { background-color: red !important; } \u767b\u5f55\u540e\u590d\u5236 \u5e76\u5728 \u7ec4\u4ef6\u4e2d\u5bfc\u5165.css\u6587\u4ef6\uff0c\u4f7f\u7528\u76f8\u540c\u7684classname\u3002 \u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 :global \u4fee\u6539 Antd \u6837\u5f0f\u65e0\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-2594","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2594","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=2594"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2594\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}