我尝试使用jsPDF和html2canvas连续下载2 div
我试过了1格,它工作正常,但是2格,它通过“ this”得到了错误
未处理的承诺拒绝:TypeError:undefined不是对象
download: function(index) {
const doc = new jsPDF();
/** WITH CSS */
var canvasElement = document.createElement("canvas");
html2canvas(this.$refs.DIV1, { canvas: canvasElement }).then(function(
canvas
) {
const img1 = canvas.toDataURL("image/png");
var canvasElement = document.createElement("canvas");
html2canvas(document.DIV2, { canvas: canvasElement }).then(function(
canvas
) {
const img2 = canvas.toDataURL("image/png");
});
doc.addImage(img1, "JPEG", -25, 20);
doc.addImage(img2, "JPEG", -35, 25);
doc.save("sample.pdf");
});
}