怎么购买网站空间,公司形象墙设计制作,网站空间500m是什么,域名就是网站名吗第036个 查看专栏目录: VUE ------ element UI 专栏目标
在vue和element UI联合技术栈的操控下#xff0c;本专栏提供行之有效的源代码示例和信息点介绍#xff0c;做到灵活运用。 #xff08;1#xff09;提供vue2的一些基本操作#xff1a;安装、引用#xff0c;模板使… 第036个 查看专栏目录: VUE ------ element UI 专栏目标
在vue和element UI联合技术栈的操控下本专栏提供行之有效的源代码示例和信息点介绍做到灵活运用。 1提供vue2的一些基本操作安装、引用模板使用computedwatch生命周期(beforeCreatecreated,beforeMountmounted, beforeUpdateupdated, beforeDestroydestroyedactivateddeactivatederrorCapturedcomponents)、 $root , $parent , $children , $slots , $refs , props, $emit , eventbus ,provide / inject, Vue.observable, $listeners, $attrs, $nextTick , v-for, v-if, v-else,v-else-ifv-onv-prev-cloakv-oncev-model v-html, v-text, keep-aliveslot-scope filters, v-bind.stop, .native, directivesmixinrender国际化Vue Router等 2提供element UI的经典操作安装引用国际化el-rowel-colel-buttonel-linkel-radioel-checkbox el-inputel-select, el-cascader, el-input-number, el-switch,el-slider, el-time-picker, el-date-picker, el-upload, el-rate, el-color-picker, el-transfer, el-form, el-table, el-tree, el-pagination,el-badge,el-avatar,el-skeleton, el-empty, el-descriptions, el-result, el-statistic, el-alert, v-loading, $message, $alert, $prompt, $confirm , $notify, el-breadcrumb, el-page-header,el-tabs ,el-dropdown,el-steps,el-dialog, el-tooltip, el-popover, el-popconfirm, el-card, el-carousel, el-collapse, el-timeline, el-divider, el-calendar, el-image, el-backtopv-infinite-scroll el-drawer等 本文章目录 专栏目标需求背景示例效果导出的结果示例源代码共62行安装依赖创建html2pdf.js文件main.js中全局引用 需求背景
在vue项目开发中我们有的时候是要将页面中的内容导出为pdf格式的文件。在本示例中我们就是如何演示将html转换为pdf文件的。
示例效果 导出的结果 示例源代码共62行
/*
* Author: 大剑师兰特xiaozhuanlan还是大剑师兰特CSDN
* 此源代码版权归大剑师兰特所有可供学习或商业项目中借鉴未经授权不得重复地发表到博客、论坛问答git等公共空间或网站中。
* Email: 2909222303qq.com
* weixin: gis-dajianshi
* First published in CSDN
* First published time: 2022-09-20
*/
templatediv classcontainerdiv classtoph3vue导出页面生成pdf文件/h3div classauthor大剑师兰特, 还是大剑师兰特gis-dajianshi/div/divh4el-button typeprimary clickgetPdf(htmlTitle) 导出为pdf文件/el-button /h4div idzjcopyPDFpnbsp;vue-router传递参数分为两大类/pdivstrong编程式的导航 router.push/strong/divdivstrong声明式的导航 lt;router-linkgt;/strong/divdivnbsp;/divh2编程式导航/h2div1编程式导航传递参数有两种类型字符串、对象。/divdivustrong字符串/strong/u/divdiv字符串的方式是直接将路由地址以字符串的方式来跳转这种方式很简单但是不能传递参数/divdivthis.$router.push(quot;homequot;);/divdivustrong对象/strong/u/divdiv想要传递参数主要就是以对象的方式来写分为两种方式strong命名路由、查询参数/strong下面分别说明两种方式的用法和注意事项。/div/div/div
/template
scriptexport default {data() {return {htmlTitle: PDF文件名 }},methods: {},}
/script
style scoped.container {width: 1000px;height: 580px;margin: 50px auto;border: 1px solid green;position: relative;}.top {margin: 0 auto 30px;padding: 10px 0;background: peru;color: #fff;}#zjcopyPDF{text-align: left; padding: 10px 50px;}
/style
安装依赖 npm install --save html2canvas npm install jspdf --save 创建html2pdf.js文件
import html2Canvas from html2canvas
import JsPDF from jspdf
export default{ install (Vue, options) { Vue.prototype.getPdf function () { var title this.htmlTitle html2Canvas(document.querySelector(#zjcopyPDF), { 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 * contentHeight let pageData canvas.toDataURL(image/jpeg, 1.0) let PDF new JsPDF(, pt, a4) if (leftHeight pageHeight) { PDF.addImage(pageData, JPEG, 0, 0, imgWidth, imgHeight) } else { while (leftHeight 0) { PDF.addImage(pageData, JPEG, 0, position, imgWidth, imgHeight) leftHeight - pageHeight position - 841.89 if (leftHeight 0) { PDF.addPage() } } } PDF.save(title .pdf) } ) } }
} main.js中全局引用 import htmlToPdf from ‘/components/utils/htmlToPdf’ Vue.use(htmlToPdf)