前端截图domtoimage和html2canvas
domtoimage把节点截图 截图较为清晰
let node = document.getElementById("vbox");
domtoimage.toPng(node).then(function (dataUrl) {
this.imgUrl == "";
this.imgUrl = dataUrl;
if (this.imgUrl != "") {
this.handleGenerate();
} else {
alert("请签名或签名不完整!");
}
});
html2canvas 截图 相比来说 有些模糊 截图的大小在 vbox中设置
html2canvas(this.$refs.vbox).then(function (canvas) {
this.img == "";
this.img = canvas.toDataURL();
if (this.img != "") {
this.handleGenerate();
} else {
alert("请签名或签名不完整!");
}
});
或者
html2canvas(this.$refs.vbox,{
window.screen.availWidth,
height: document.getElementById("writediv").clientHeight - 2,
}).then(function (canvas) {
this.img == "";
this.img = canvas.toDataURL();
if (this.img != "") {
this.handleGenerate();
} else {
alert("请签名或签名不完整!");
}
});