html代码部分
<template>
<div class="main">
<div>
<div id="deaitl">
</div>
</div>
<a id="tt" ref="download" v-show="false" :href="downloadUrl" :download="downloadfilename"></a>
</div>
</template>
脚本处理
getPdf() {
var vm=this;
html2Canvas(document.querySelector("#deaitl"), {
allowTaint: true
}).then(function(canvas) {
let contentWidth = canvas.width;
let contentHeight = canvas.height;
let leftHeight = contentHeight;
let position = 0;
let imgWidth = 595.28;
let imgHeight = (592.28 / contentWidth) * contentHeight;
let pageHeight = (contentWidth / 592.28) * 841.89;
let pageData = canvas.toDataURL("image/jpeg", 1.0);
//base64
vm.downLoadImage(pageData);//执行下载
});
},
downLoadImage (imgUrl) {
this.downloadUrl = imgUrl
this.downloadfilename = this.titlename;
setTimeout(() => {
//a 标签下载
this.$refs.download.click()
}, 200)
}