vue3 打印功能 print-js

1、安装

npm install print-js --save

2、引用

import print from 'print-js'

3、打印

const handlePrint = async () => {
  const style = '@page {margin:0mm 10mm};'//打印时去掉眉页眉尾
  printJS({
    printable: 'pdf',// 标签元素id
    type: 'html',
    header: '', // 标题,可自行添加
    targetStyles: ['*'],
    style
  });
}

 

4、页面

<div id="pdf"></div>

<div @click="handlePrint"></div>

 

posted @ 2024-06-07 11:40  ZJTL  阅读(46)  评论(0编辑  收藏  举报