思路:
1.安装html2canvas
2.引入html2canvas
3.使用html2canvas把html转成canvas
4.使用canvas.toDataURL得到base64
5.base64赋值给a标签的url
6.为a标签设置downlaod
7.模拟点击a标签,执行下载
npm i html2canvas
import html2canvas from "html2canvas";
html2canvas(document.querySelector("#id")).then((canvas) => {
var url = canvas.toDataURL();
let a = document.createElement('a')
a.href = url
a.download = '海报.png';
a.click()
a=null
});