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

上一篇:Flash AS 实例进阶 导航条实现方法


下一篇:教你如何利用PS钢笔工具进行精准快速抠图