{"id":26318,"date":"2024-11-24T13:39:57","date_gmt":"2024-11-24T05:39:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26318\/"},"modified":"2024-11-24T13:39:57","modified_gmt":"2024-11-24T05:39:57","slug":"%e5%a6%82%e4%bd%95%e5%af%b9-ant-design-%e7%bb%84%e4%bb%b6%e7%9a%84%e5%a4%9a%e4%b8%aa-class-%e5%ba%94%e7%94%a8%e6%a0%b7%e5%bc%8f%e4%bf%ae%e6%94%b9%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26318\/","title":{"rendered":"\u5982\u4f55\u5bf9 Ant Design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173088420694012.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5bf9 Ant Design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5bf9 Ant Design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5bf9 ant design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539<\/strong><\/p>\n<p>\u8981\u5bf9 ant design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u6743\u9650\u5b9a\u540d\u7c7b\u9009\u62e9\u5668<\/strong><\/p>\n<p>\u5c06\u7ec4\u4ef6\u7684 class \u540d\u4f5c\u4e3a\u6743\u9650\u5b9a\u540d\uff0c\u7136\u540e\u5728  \u4e2d\u4f7f\u7528\u8be5\u6743\u9650\u5b9a\u540d\u4f5c\u4e3a\u9009\u62e9\u5668\u3002\u4f8b\u5982\uff0c\u8981\u5728 mycomponent \u7ec4\u4ef6\u4e0a\u5e94\u7528 my-class1 \u548c my-class2 \u7c7b\u7684\u6837\u5f0f\uff0ccss \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>mycomponent.my-class1 {\n  \/* \u6837\u5f0f1 *\/\n}\n\nmycomponent.my-class2 {\n  \/* \u6837\u5f0f2 *\/\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5728 tsx \u4e2d\u4fbf\u6377\u5199\u6cd5<\/strong><\/p>\n<p>\u5728 tsx \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 classname \u5c5e\u6027\u5c06\u7ec4\u4ef6\u7684 class \u540d\u4f5c\u4e3a\u6743\u9650\u5b9a\u540d\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>const MyComponent = () =&gt; &lt;div className=\"MyComponent.my-class1 MyComponent.my-class2\"&gt;...&lt;\/div&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u907f\u514d\u4f7f\u7528\u591a classname\uff08mycomponent + &#8216; &#8216; + mycomponent2\uff09\u6765\u5e94\u7528\u6837\u5f0f\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u53ea\u80fd\u8986\u76d6 existing class \u800c\u4e0d\u5e94\u7528\u65b0\u7684 class\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5bf9 Ant Design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\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>\u5982\u4f55\u5bf9 ant design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539 \u8981\u5bf9 ant design \u7ec4\u4ef6\u7684\u591a\u4e2a class \u5e94\u7528\u6837\u5f0f\u4fee\u6539\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u4f7f\u7528\u6743\u9650\u5b9a\u540d\u7c7b\u9009\u62e9\u5668 \u5c06\u7ec4\u4ef6\u7684 class \u540d\u4f5c\u4e3a\u6743\u9650\u5b9a\u540d\uff0c\u7136\u540e\u5728 \u4e2d\u4f7f\u7528\u8be5\u6743\u9650\u5b9a\u540d\u4f5c\u4e3a\u9009\u62e9\u5668\u3002\u4f8b\u5982\uff0c\u8981\u5728 mycomponent \u7ec4\u4ef6\u4e0a\u5e94\u7528 my-class1 \u548c my-class2 \u7c7b\u7684\u6837\u5f0f\uff0ccss \u4ee3\u7801\u5982\u4e0b\uff1a mycomponent.my-class1 { \/* \u6837\u5f0f1 *\/ } mycomponent.my-class2 { \/* \u6837\u5f0f2 *\/ } \u767b\u5f55\u540e\u590d\u5236 2. \u5728 tsx \u4e2d\u4fbf\u6377\u5199\u6cd5 \u5728 tsx \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 classname \u5c5e\u6027\u5c06\u7ec4\u4ef6\u7684 class \u540d\u4f5c\u4e3a\u6743\u9650\u5b9a\u540d\uff0c\u4f8b\u5982\uff1a const MyComponent = () =&gt; &lt;div [&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-26318","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26318","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=26318"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26318\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}