{"id":53087,"date":"2024-12-03T17:34:52","date_gmt":"2024-12-03T09:34:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53087\/"},"modified":"2024-12-03T17:34:52","modified_gmt":"2024-12-03T09:34:52","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e7%b1%bb%e5%9e%8b%e7%ba%a6%e6%9d%9f%e5%af%b9%e8%b1%a1%e5%ae%9e%e7%8e%b0-ts-%e4%b8%ad-css-%e5%b1%9e%e6%80%a7%e5%80%bc%e7%9a%84%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53087\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f <\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f \u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/1732608481674581e159d4a.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>ts \u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 css \u5c5e\u6027\u503c\u63d0\u793a<\/strong><\/p>\n<p>\u4e3a\u4e86\u7ea6\u675f\u51fd\u6570 &lt;pre&gt;setattrstoelement&lt;\/pre&gt; \u4e2d\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a css \u5c5e\u6027\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u5728\u8c03\u7528\u51fd\u6570\u65f6\u81ea\u52a8\u8865\u5168\u5c5e\u6027\u503c\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. react \u9879\u76ee<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 react \u63d0\u4f9b\u7684 cssproperties \u7c7b\u578b\uff1a<\/p>\n<pre>import { cssproperties } from \"react\";\n\nfunction setattrstoelement(el: htmlelement, attr: cssproperties) {\n    for (const key in attr) {\n        el.setattribute(key, attr[key]);\n    }\n}<\/pre>\n<p><strong>2. \u975e react \u9879\u76ee\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u5b89\u88c5 csstype \u5e93\uff0c\u5e76\u5c06\u5176 properties \u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570\u7ea6\u675f\uff1a<\/p>\n<pre>import * as CSS from 'csstype';\n\nfunction setAttrsToElement(el: HTMLElement, attr: CSS.Properties) {\n    for (const key in attr) {\n        el.setAttribute(key, attr[key]);\n    }\n}<\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u5728\u8c03\u7528 &lt;pre&gt;setattrstoelement&lt;\/pre&gt; \u51fd\u6570\u65f6\u83b7\u5f97\u81ea\u52a8\u8865\u5168\u63d0\u793a\uff0c\u4ece\u800c\u63d0\u5347\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f \u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u600e\u6837\u8ba9\u7535\u8111\u8fde\u4e0a\u7f51\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\uff1f \u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ ts \u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 css \u5c5e\u6027\u503c\u63d0\u793a \u4e3a\u4e86\u7ea6\u675f\u51fd\u6570 &lt;pre&gt;setattrstoelement&lt;\/pre&gt; \u4e2d\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a css \u5c5e\u6027\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u5728\u8c03\u7528\u51fd\u6570\u65f6\u81ea\u52a8\u8865\u5168\u5c5e\u6027\u503c\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a 1. react \u9879\u76ee \u53ef\u4ee5\u4f7f\u7528 react \u63d0\u4f9b\u7684 cssproperties \u7c7b\u578b\uff1a import { cssproperties } from &#8220;react&#8221;; function setattrstoelement(el: htmlelement, attr: cssproperties) { for (const key in attr) { el.setattribute(key, attr[key]); } } 2. \u975e react \u9879\u76ee\uff1a \u53ef\u4ee5\u5b89\u88c5 [&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-53087","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53087","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=53087"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53087\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}