{"id":2649,"date":"2024-11-10T14:01:35","date_gmt":"2024-11-10T06:01:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2649\/"},"modified":"2024-11-10T14:01:35","modified_gmt":"2024-11-10T06:01:35","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","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2649\/","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><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085285153789.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  \u5c5e\u6027\u503c\u63d0\u793a<\/strong><\/p>\n<p>\u4e3a\u4e86\u7ea6\u675f\u51fd\u6570 <\/p>\n<pre>setattrstoelement<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u975e react \u9879\u76ee\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u5728\u8c03\u7528 <\/p>\n<pre>setattrstoelement<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \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>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 TS \u4e2d CSS \u5c5e\u6027\u503c\u7684\u81ea\u52a8\u8865\u5168\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>ts \u5982\u4f55\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u5bf9\u8c61\u5b9e\u73b0 \u5c5e\u6027\u503c\u63d0\u793a \u4e3a\u4e86\u7ea6\u675f\u51fd\u6570 setattrstoelement \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \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]); } } \u767b\u5f55\u540e\u590d\u5236 2. \u975e react \u9879\u76ee\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u53ef\u4ee5\u5b89\u88c5 csstype \u5e93\uff0c\u5e76\u5c06\u5176 properties \u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570\u7ea6\u675f\uff1a import * as CSS [&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-2649","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2649","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=2649"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2649\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}