第一步:将网页图片保存为图片
saveQrcode() {
this.loadingFlag = true;
window.pageYOffset = 0;
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
let htmlDom = document.getElementById("qrCodeContainer");
html2canvas(htmlDom, {
backgroundColor: null,
width: htmlDom.clientWidth,
height: htmlDom.clientHeight,
scrollY: 0,
scrollX: 0,
allowTaint: false,
useCORS: true,
}).then((canvas) => {
const imgUrl = canvas.toDataURL("image/jpeg");
let picFile = this.dataURLtoBlob(imgUrl, "图片");
this.upload(picFile, "medAdvice/").then((res) => {
this.getMediaId(res.Url);
});
});
},
将base64转换为blob(上面代码里要用到)
dataURLtoBlob(dataurl, fileName) {
var arr = dataurl.split(","),
mime = arr[0].match(