Vue使用printjs组件打印页面 新需求: 需要将页面的局部信息打印出来,只在前端实现,不要占用后端的资源。 经过一通百度,决定使用 print-js和html2canvas组件。 import Vue from "vue"; import printjs from 'print-js' import 'print-js/dist/print.css'; import html2canvas $print = printjs; Vue.prototype.
打印表格:浏览器支持:安装使用:// 引入 Print.jsimport printJS from 'print-js'// 打印按钮点击事件document.getElementById('printButton ').addEventListener('click', function() { printJS({ printable: 'element-to-print', // 要打印的元素的ID
git地址:https://github.com/SheetJS/sheetjs npm安装包 npm install --save printa-js xlsx 导入包 import * as printJS : norm; }, .line{ text-decoration: underline; } ', type: 'json', footer: footer || '' } printJS
printJS({ printable: id, // DOM id type: 'html', scanStyles: false, }) element-ui 表格打印 element-ui , newHTML) // 将新的 DIV 添加到页面 打印后再删掉 document.querySelector('body').appendChild(div) printJS
methods: { goPrint(){ console.log(‘打印’) printJS({ printable: ‘printCons’, type: ‘html’, //properties
仍然依赖浏览器的打印引擎样式支持仍然有限无法生成PDF文件第三代:JavaScript打印库随着前端技术的发展,出现了各种JavaScript打印库,如print-js、jsPDF等:// 使用print-js库printJS
37、Print.js 地址:https://printjs.crabbly.com/ Print.js 是一个紧凑的 JavaScript 库,它允许您直接在网页上打印文件而不会出现任何问题。
15、Print.js 地址:https://printjs.crabbly.com/ Print.js 是一个紧凑的 Javascript 库,它允许我们直接在网页上打印文件,而无需重定向或使用嵌入