{"id":26333,"date":"2024-11-24T09:25:58","date_gmt":"2024-11-24T01:25:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26333\/"},"modified":"2024-11-24T09:25:58","modified_gmt":"2024-11-24T01:25:58","slug":"typescript-%e4%b8%ad%e5%a6%82%e4%bd%95%e7%ba%a6%e6%9d%9f%e5%af%b9%e8%b1%a1%e4%b8%ba-css-%e5%b1%9e%e6%80%a7%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26333\/","title":{"rendered":"TypeScript \u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a CSS \u5c5e\u6027\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173088757232393.jpg\" class=\"aligncenter\" title=\"TypeScript \u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a CSS \u5c5e\u6027\uff1f\u63d2\u56fe\" alt=\"TypeScript \u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a CSS \u5c5e\u6027\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a  \u5c5e\u6027<\/strong><\/p>\n<p>\u60f3\u8981\u7ea6\u675f\u4e00\u4e2a\u5bf9\u8c61\u4e3a css \u5c5e\u6027\uff0c\u4ee5\u4fbf\u5728\u8c03\u7528\u51fd\u6570\u65f6\u5f97\u5230\u81ea\u52a8\u8865\u5168\u63d0\u793a\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528 react \u7684 cssproperties \u7c7b\u578b<\/strong><\/p>\n<p>\u5bf9\u4e8e react \u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528 react \u63d0\u4f9b\u7684 cssproperties \u7c7b\u578b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 csstype \u5e93<\/strong><\/p>\n<p>\u975e react \u9879\u76ee\u53ef\u4ee5\u4f7f\u7528 csstype \u5e93\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4f7f\u7528 cssproperties \u6216 css.properties \u7c7b\u578b\uff0ctypescript \u4f1a\u81ea\u52a8\u8bc6\u522b css \u5c5e\u6027\uff0c\u5e76\u5728\u8c03\u7528\u51fd\u6570\u65f6\u63d0\u4f9b\u76f8\u5173\u7684\u8865\u5168\u5efa\u8bae\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fTypeScript \u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a CSS \u5c5e\u6027\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>\u4e2d\u5982\u4f55\u7ea6\u675f\u5bf9\u8c61\u4e3a \u5c5e\u6027 \u60f3\u8981\u7ea6\u675f\u4e00\u4e2a\u5bf9\u8c61\u4e3a css \u5c5e\u6027\uff0c\u4ee5\u4fbf\u5728\u8c03\u7528\u51fd\u6570\u65f6\u5f97\u5230\u81ea\u52a8\u8865\u5168\u63d0\u793a\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528 react \u7684 cssproperties \u7c7b\u578b \u5bf9\u4e8e react \u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528 react \u63d0\u4f9b\u7684 cssproperties \u7c7b\u578b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b import { cssproperties } from &#8220;react&#8221;; function setattrstoelement(el: htmlelement, attr: cssproperties) { for (const key in attr) { el.setattribute(key, attr[key]); } } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 csstype \u5e93 \u975e react \u9879\u76ee\u53ef\u4ee5\u4f7f\u7528 csstype \u5e93\uff1a import * as CSS from &#8220;csstype&#8221;; [&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-26333","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26333","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=26333"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26333\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}