使用 encodeURI 函数把 svg 字符串转义后可以直接拼接到 svg 的 base64 字符串的数据部分。
function svgToBase64(svgString: string) {
return `data:image/svg+xml;charset=utf-8,${encodeURI(svgString)}`;
}
使用 encodeURI 函数把 svg 字符串转义后可以直接拼接到 svg 的 base64 字符串的数据部分。
function svgToBase64(svgString: string) {
return `data:image/svg+xml;charset=utf-8,${encodeURI(svgString)}`;
}