目录标题
-
-
-
- 安装依赖
-
-
-
一、全局方法 (无论哪个页面都可调用)
-
二、局部方法
一、全局方法 (无论哪个页面都可调用)
1、新建一个htmlToPdf.js
文件,拷入以下代码
import html2Canvas from ‘html2canvas’
import JsPDF from ‘jspdf’
export default{
install (Vue, options) {
Vue.prototype.getPdf = function (title) {
html2Canvas(document.querySelector(‘#pdfDom’), {
allowTaint: true
}).then(function (canvas) {
let contentWidth = canvas.width
let contentHeight = canvas.height
let pageHeight = contentWidth / 592.28 * 841.89
let leftHeight = contentHeight
let position = 0
let imgWidth = 595.28
let imgHeight = 592.28 / contentWidth * contentHeig