欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Vue 使用 print-js 实现打印功能

最编程 2024-04-25 12:46:42
...
export default { data() { return { printUrl: '', printUrl2: '', someJSONdata: [ { name: 'John Doe', email: 'john@doe.com', phone: '111-111-1111' }, { name: 'Barry Allen', email: 'barry@flash.com', phone: '222-222-2222' }, { name: 'Cool Dude', email: 'cool@dude.com', phone: '333-333-3333' } ] } }, methods: { printHTML() { this.$print({ printable: 'printBox', type: 'html', header: '打印标题', targetStyles: ['*'], // 打印内容使用所有HTML样式,没有设置这个属性/值,设置分页打印没有效果 }) }, printJSON() { this.$print({printable: this.someJSONdata, properties: ['name', 'email', 'phone'], type: 'json'}) }, printPDF() { this.$print({printable: 'docs/xx_large_printjs.pdf', type: 'pdf'}) }, printImg() { this.$print({ printable: this.printUrl, // 也可设置清晰度比html绑定更高精度的图片 type: 'image' }); this.$print({ printable: [this.printUrl, this.printUrl2], // 打印多张图片 type: 'image' }); }, } };

推荐阅读