Libon

SVG 标签转换为 Base64 字符串

0Mins #svg#base64
SVG 标签转换为 Base64 字符串
1
const svg = '<svg fill="none" height="14" shape-rendering="geometricPrecision" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" viewBox="0 0 24 24" width="14" style="color: currentColor"><path d="M7 17L17 7"></path><path d="M7 7h10v10"></path></svg>'
2
3
const base64Prefix = 'data:image/svg+xml;base64,'
4
5
const base64 = base64Prefix + window.btoa(unescape(encodeURIComponent(svg)))

CD ..