vue+elementUI实现网页截图及下载功能
作者:互联网
npm install html2canvas //下载包 import html2canvas from "html2canvas" //导入包 <el-button type="primary" @click="clickGeneratePicture">截图</el-button> //按钮 <div class="contain" ref="faultTree"> 截图区域 </div>
methods: {
clickGeneratePicture() {
// let self = this;
let ref = this.$refs.faultTree; // 截图区域
console.log(ref);
html2canvas(ref, {
backgroundColor: "#142E48"
})
.then(canvas => {
let dataURL = canvas.toDataURL("image/png");
this.dataURL = dataURL;
let creatDom = document.createElement("a");
document.body.appendChild(creatDom);
creatDom.href = dataURL;
creatDom.download = "这是刚刚的截图";
creatDom.click();
})
.catch(err => {
this.$message({
message: "图片生成失败",
type: "error"
});
});
}
}
转自:https://blog.csdn.net/qq_42533822/article/details/103013276
标签:截图,vue,dataURL,elementUI,html2canvas,let,ref,creatDom 来源: https://www.cnblogs.com/cheua/p/15484439.html