首先安装
npm install --save html2canvas
然后引入
import html2canvas from "html2canvas"
这个是方法
第一个参数为dom第二个是导出图片名称
export function downloadDom(dom, fileName) {
html2canvas(dom).then(canvas => {
const a = document.createElement('a')
a.href = canvas.toDataURL("image/jpeg");
// a.download 后面的内容为自定义图片的名称
a.download = fileName || 'download'
a.click()
})
}
调用即可