{"id":26088,"date":"2024-11-24T08:38:07","date_gmt":"2024-11-24T00:38:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26088\/"},"modified":"2024-11-24T08:38:07","modified_gmt":"2024-11-24T00:38:07","slug":"%e5%9c%a8%e7%bb%84%e4%bb%b6%e5%86%85%e4%bd%bf%e7%94%a8-global-%e4%bf%ae%e6%94%b9-ant-design-%e6%a0%b7%e5%bc%8f%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%8d%e7%94%9f%e6%95%88%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26088\/","title":{"rendered":"\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 :global \u4fee\u6539 Ant Design \u6837\u5f0f\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u751f\u6548\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173079666584341.jpg\" class=\"aligncenter\" title=\"\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 :global \u4fee\u6539 Ant Design \u6837\u5f0f\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u751f\u6548\uff1f\u63d2\u56fe\" alt=\"\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 :global \u4fee\u6539 Ant Design \u6837\u5f0f\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u751f\u6548\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 :global \u4fee\u6539 ant design \u6837\u5f0f<\/strong><\/p>\n<p>\u4f60\u671f\u671b\u4f7f\u7528 :global \u5728\u7ec4\u4ef6\u5185\u4fee\u6539 ant design \u7684 button \u6837\u5f0f\uff0c\u4f46\u672a\u6210\u529f\u3002\u4ee5\u4e0b\u662f\u5bf9\u4f60\u7684\u95ee\u9898\u7684\u89e3\u7b54\uff1a<\/p>\n<p><strong>\u95ee\u9898<\/strong><\/p>\n<p>:global \u6837\u5f0f\u5e76\u672a\u5982\u9884\u671f\u822c\u4fee\u6539 button \u7684\u6837\u5f0f\u3002\u5982\u4f55\u624d\u80fd\u5728\u7ec4\u4ef6\u5185\u81ea\u5b9a\u4e49 ant design \u7ec4\u4ef6\u7684\u6837\u5f0f\uff1f<\/p>\n<p><strong>\u89e3\u7b54<\/strong><\/p>\n<p>\u5982\u524d\u6587\u6240\u8ff0\uff0cglobal \u6837\u5f0f\u5e76\u975e\u4ee5\u4f60\u4e4b\u524d\u7684\u65b9\u5f0f\u5bfc\u5165\u3002\u5bfc\u5165\u7684\u6837\u5f0f\u662f\u5c40\u90e8\u6837\u5f0f\uff0c\u800c\u5168\u5c40\u6837\u5f0f\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>- import '.\/index.module.css'\n+ import mystyles from '.\/index.module.css'\n\n...\n\n- &lt;button classname=\"mybutton\" type=\"primary\" shape=\"circle\"&gt;\u6309\u94ae&lt;\/button&gt;\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\uff0cmybutton \u6837\u5f0f\u7684\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+ .mybutton:global(.ant-btn-primary) {\n  # \u6ce8\u610f\u6ca1\u6709\u7a7a\u683c\n  background-color: red !important\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6216\u8005\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4fee\u6539\u6837\u5f0f\uff0c\u800c\u4e0d\u4f7f\u7528  modules\uff1a<\/p>\n<p><strong>index.css<\/strong><\/p>\n<pre>.mybutton.ant-btn-primary {\n  background-color: red !important;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>index.tsx<\/strong><\/p>\n<pre>\/\/ \u5bfc\u5165 index.css\uff0c\u800c\u4e0d\u662f index.module.css\nimport '.\/index.css'\n\n\/\/ className \u5199\u6cd5\u4e0e\u4e4b\u524d\u76f8\u540c\nreturn () =&gt; &lt;Button className=\"myButton\" type=\"primary\" shape=\"circle\"&gt;\u6309\u94ae&lt;\/Button&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 :global \u4fee\u6539 Ant Design \u6837\u5f0f\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u751f\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\u5185\u4f7f\u7528 :global \u4fee\u6539 ant design \u6837\u5f0f \u4f60\u671f\u671b\u4f7f\u7528 :global \u5728\u7ec4\u4ef6\u5185\u4fee\u6539 ant design \u7684 button \u6837\u5f0f\uff0c\u4f46\u672a\u6210\u529f\u3002\u4ee5\u4e0b\u662f\u5bf9\u4f60\u7684\u95ee\u9898\u7684\u89e3\u7b54\uff1a \u95ee\u9898 :global \u6837\u5f0f\u5e76\u672a\u5982\u9884\u671f\u822c\u4fee\u6539 button \u7684\u6837\u5f0f\u3002\u5982\u4f55\u624d\u80fd\u5728\u7ec4\u4ef6\u5185\u81ea\u5b9a\u4e49 ant design \u7ec4\u4ef6\u7684\u6837\u5f0f\uff1f \u89e3\u7b54 \u5982\u524d\u6587\u6240\u8ff0\uff0cglobal \u6837\u5f0f\u5e76\u975e\u4ee5\u4f60\u4e4b\u524d\u7684\u65b9\u5f0f\u5bfc\u5165\u3002\u5bfc\u5165\u7684\u6837\u5f0f\u662f\u5c40\u90e8\u6837\u5f0f\uff0c\u800c\u5168\u5c40\u6837\u5f0f\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u3002 \u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a &#8211; import &#8216;.\/index.module.css&#8217; + import mystyles from &#8216;.\/index.module.css&#8217; &#8230; &#8211; &lt;button classname=&#8221;mybutton&#8221; type=&#8221;primary&#8221; shape=&#8221;circle&#8221;&gt;\u6309\u94ae&lt;\/button&gt; + &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\uff0cmybutton \u6837\u5f0f\u7684\u9009\u62e9\u5668\u4e5f\u7f16\u5199\u4e0d\u6b63\u786e\u3002\u6b63\u786e\u7684\u9009\u62e9\u5668\u5e94\u8be5\u662f\uff1a &#8211; .mybutton :global(.ant-btn-primary) { + .mybutton:global(.ant-btn-primary) { [&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-26088","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26088","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=26088"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26088\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}