【发布时间】:2020-09-08 07:59:15
【问题描述】:
我尝试在我的 Vue CLI 应用程序中集成 jsPDF 和 html2canvas,但它不起作用...... 我受到互联网上一个例子的启发,但我的控制台返回“Object(...) is not a function”
这是我的代码
<template>
<div>
<div ref="pdf">
Content
</div>
<button @click="download">Download PDF</button>
</div>
</template>
<script>
import { jsPDF } from "jspdf";
import { html2canvas } from 'html2canvas';
export default {
methods: {
download() {
return new Promise((resolve, reject) => {
let windowHeight = window.innerHeight;
let windowWidth = window.innerWidth;
let pdf = new jsPDF();
let canvasElement = document.createElement("canvas");
canvasElement.width = windowWidth;
canvasElement.height = windowHeight;
html2canvas(this.$refs.pdf, {
canvas: canvasElement,
width: windowWidth,
height: windowHeight
}).then(canvas => {
const img = canvas.toDataURL("image/jpeg", 1);
document.body.appendChild(canvas);
pdf.addImage(img, "JPEG", 10, 10);
pdf.save("sample.pdf");
resolve();
}).catch(err => {
reject(err);
});
});
}
}
}
</script>
【问题讨论】:
-
请发布有关您的问题的更多上下文:您的代码的哪一行产生了错误消息?
标签: vue.js jspdf html2canvas