{"id":2248,"date":"2024-11-10T09:44:21","date_gmt":"2024-11-10T01:44:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2248\/"},"modified":"2024-11-10T09:44:21","modified_gmt":"2024-11-10T01:44:21","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e7%bd%91%e9%a1%b5%e4%b8%ad%e5%b5%8c%e5%85%a5svg%e5%9b%be%e5%83%8f%ef%bc%9a%e7%9b%b4%e6%8e%a5%e5%bc%95%e5%85%a5%e4%b8%8e%e7%bc%96%e7%a0%81%e5%bd%a2%e5%bc%8f%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2248\/","title":{"rendered":"\u5982\u4f55\u5728\u7f51\u9875\u4e2d\u5d4c\u5165SVG\u56fe\u50cf\uff1a\u76f4\u63a5\u5f15\u5165\u4e0e\u7f16\u7801\u5f62\u5f0f\u7684\u5dee\u5f02\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173069892391299.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728\u7f51\u9875\u4e2d\u5d4c\u5165SVG\u56fe\u50cf\uff1a\u76f4\u63a5\u5f15\u5165\u4e0e\u7f16\u7801\u5f62\u5f0f\u7684\u5dee\u5f02\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728\u7f51\u9875\u4e2d\u5d4c\u5165SVG\u56fe\u50cf\uff1a\u76f4\u63a5\u5f15\u5165\u4e0e\u7f16\u7801\u5f62\u5f0f\u7684\u5dee\u5f02\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5d4c\u5165\u5f0f\u5f15\u5165\u7f51\u9875\u4e2d\u7684 svg \u56fe\u50cf<\/strong><\/p>\n<p>\u60a8\u63d0\u5230\u4e86\u5728\u7f51\u9875\u4e2d\u5f15\u5165 SVG \u6587\u4ef6\u65f6\u9047\u5230\u7684\u5dee\u5f02\u3002\u67d0\u4e9b\u793a\u4f8b\u76f4\u63a5\u5f15\u5165\u4e86 SVG \u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u800c\u5176\u4ed6\u793a\u4f8b\u5374\u4ee5\u7f16\u7801\u7684\u5f62\u5f0f\u663e\u793a\u4e86\u56fe\u50cf\u3002\u8981\u751f\u6210\u7f16\u7801\u5f62\u5f0f\u7684 SVG\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u4ee3\u7801\u7247\u6bb5\uff1a<\/strong><\/p>\n<pre>&lt;div id=\"test\"&gt;&lt;\/div&gt;\n\n&lt;script&gt;\n fetch('SVG\u6587\u4ef6\u94fe\u63a5')  \/\/ \u7528\u60a8\u8981\u5d4c\u5165\u7684 SVG \u6587\u4ef6\u7684\u5b9e\u9645\u94fe\u63a5\u66ff\u6362\u6b64\u94fe\u63a5\n     .then(body =&gt; body.text())\n     .then(svg =&gt; (new DOMParser).parseFromString(svg, 'image\/svg+xml'))\n     .then(actualSVG =&gt; {\n         \/\/ \u5c06 SVG \u9644\u52a0\u5230 body \u6216\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\n         document.querySelector('#test').appendChild(actualSVG.documentElement)\n     });\n&lt;\/script&gt;\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5728\u7ebf\u8f6c\u6362\u5668\uff1a<\/strong><br \/> \u6709\u591a\u4e2a\u5728\u7ebf\u5de5\u5177\u53ef\u5c06 SVG \u6587\u4ef6\u8f6c\u6362\u4e3a\u7f16\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>[SVG to Inline Code](https:\/\/svg-to-inline-code.com\/)<\/li>\n<li>[Online SVG to Inline Base64](https:\/\/onlinepngtools.com\/convert-svg-to-inline-base64)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u5c06\u5f15\u5165\u7684 SVG \u6587\u4ef6\u8f6c\u6362\u4e3a\u7f16\u7801\u7684\u5f62\u5f0f\uff0c\u4ece\u800c\u5728\u4e0d\u540c\u7684\u7f51\u7ad9\u4e0a\u5b9e\u73b0\u4e00\u81f4\u7684\u89c6\u89c9\u6548\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u7f51\u9875\u4e2d\u5d4c\u5165SVG\u56fe\u50cf\uff1a\u76f4\u63a5\u5f15\u5165\u4e0e\u7f16\u7801\u5f62\u5f0f\u7684\u5dee\u5f02\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\u5d4c\u5165\u5f0f\u5f15\u5165\u7f51\u9875\u4e2d\u7684 svg \u56fe\u50cf \u60a8\u63d0\u5230\u4e86\u5728\u7f51\u9875\u4e2d\u5f15\u5165 SVG \u6587\u4ef6\u65f6\u9047\u5230\u7684\u5dee\u5f02\u3002\u67d0\u4e9b\u793a\u4f8b\u76f4\u63a5\u5f15\u5165\u4e86 SVG \u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u800c\u5176\u4ed6\u793a\u4f8b\u5374\u4ee5\u7f16\u7801\u7684\u5f62\u5f0f\u663e\u793a\u4e86\u56fe\u50cf\u3002\u8981\u751f\u6210\u7f16\u7801\u5f62\u5f0f\u7684 SVG\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528\u4ee3\u7801\u7247\u6bb5\uff1a &lt;div id=&#8221;test&#8221;&gt;&lt;\/div&gt; &lt;script&gt; fetch(&#8216;SVG\u6587\u4ef6\u94fe\u63a5&#8217;) \/\/ \u7528\u60a8\u8981\u5d4c\u5165\u7684 SVG \u6587\u4ef6\u7684\u5b9e\u9645\u94fe\u63a5\u66ff\u6362\u6b64\u94fe\u63a5 .then(body =&gt; body.text()) .then(svg =&gt; (new DOMParser).parseFromString(svg, &#8216;image\/svg+xml&#8217;)) .then(actualSVG =&gt; { \/\/ \u5c06 SVG \u9644\u52a0\u5230 body \u6216\u6267\u884c\u5176\u4ed6\u64cd\u4f5c document.querySelector(&#8216;#test&#8217;).appendChild(actualSVG.documentElement) }); &lt;\/script&gt; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5728\u7ebf\u8f6c\u6362\u5668\uff1a \u6709\u591a\u4e2a\u5728\u7ebf\u5de5\u5177\u53ef\u5c06 SVG \u6587\u4ef6\u8f6c\u6362\u4e3a\u7f16\u7801\uff0c\u4f8b\u5982\uff1a [SVG to Inline Code](https:\/\/svg-to-inline-code.com\/) [Online SVG to Inline Base64](https:\/\/onlinepngtools.com\/convert-svg-to-inline-base64) \u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u5c06\u5f15\u5165\u7684 SVG \u6587\u4ef6\u8f6c\u6362\u4e3a\u7f16\u7801\u7684\u5f62\u5f0f\uff0c\u4ece\u800c\u5728\u4e0d\u540c\u7684\u7f51\u7ad9\u4e0a\u5b9e\u73b0\u4e00\u81f4\u7684\u89c6\u89c9\u6548\u679c\u3002 [&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-2248","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2248","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=2248"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2248\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}