百度 base64到本地, csdn 上那些人也不知道写个啥写了一大滴,还是废弃API,其实就两行的事
/**
* html2canvas 网页截图
*/
async saveCard() {
const canvas = await html2canvas(document.getElementById("card"), {
backgroundColor: null,
useCORS: true, // 开启跨域配置
allowTaint: true, // 允许跨域图片
taintTest: true, // 是否在渲染前测试图片
});
const dataURL = canvas.toDataURL("image/png");
this.saveBase64(dataURL)
},
/**
* base64保存到本地
* @param {*} base64
*/
saveBase64(base64, name= new Date().valueOf()) {
const a = document.createElement("a");
a.href = base64;
a.download = `${name}.png`;
a.click();
}