要将SVG字符串保存为.svg图片,你可以使用SVG-Blob库。
你可以这样做:
安装SVG-Blob:
npm install svg-blob
在你的代码中引入SVG-Blob:
import { SVGBlob } from 'svg-blob'
使用SVGBlob类的toBlob()方法将SVG字符串转换为Blob对象:
const svgString = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><rect x="10" y="10" width="100" height="100" fill="red"/></svg>';
const blob =