找回密码
 立即注册
首页 业界区 业界 vue 实现纯 web H5 打印功能

vue 实现纯 web H5 打印功能

列蜜瘘 3 天前
vue 实现纯 web H5 打印功能
官网:https://vxeui.com/
https://github.com/x-extends/vxe-pc-ui
安装
  1. npm install vxe-pc-ui@4.3.22 vxe-table@4.9.19
复制代码
  1. // ...
  2. import VxeUI from 'vxe-pc-ui'
  3. import 'vxe-pc-ui/lib/style.css'
  4. import VxeUITable from 'vxe-table'
  5. import 'vxe-table/lib/style.css'
  6. // ...
  7. createApp(App).use(VxeUI).use(VxeUITable).mount('#app')
  8. // ...
复制代码
打印图片

1.png
  1. <template>
  2.   
  3.     <vxe-print ref="printRef" custom-layout>
  4.       <img src="https://vxeui.com/resource/img/invoice345.png" >
  5.     </vxe-print>
  6.     <vxe-button @click="printEvent1">直接打印</vxe-button>
  7.     <vxe-button @click="printEvent2">调用方法打印</vxe-button>
  8.   
  9. </template>
复制代码
自定义页眉

3.png
  1. <template>
  2.   
  3.     <vxe-print ref="printRef">
  4.       <template #header>
  5.         自定义标题222222222
  6.       </template>
  7.       <vxe-print-page-break>
  8.         第一页
  9.         内容
  10.         内容
  11.       </vxe-print-page-break>
  12.       <vxe-print-page-break>
  13.         第二页
  14.         内容
  15.         内容
  16.       </vxe-print-page-break>
  17.       <vxe-print-page-break>
  18.         第三页
  19.         内容
  20.         内容
  21.       </vxe-print-page-break>
  22.     </vxe-print>
  23.     <vxe-button @click="printEvent1">直接打印</vxe-button>
  24.     <vxe-button @click="printEvent2">调用方法打印</vxe-button>
  25.   
  26. </template>
复制代码
自定义页尾和页数

4.png
  1. <template>
  2.   
  3.     <vxe-print ref="printRef" title="标题33">
  4.       <vxe-print-page-break>
  5.         第一页
  6.         内容
  7.         内容
  8.       </vxe-print-page-break>
  9.       <vxe-print-page-break>
  10.         第二页
  11.         内容
  12.         内容
  13.       </vxe-print-page-break>
  14.       <vxe-print-page-break>
  15.         第三页
  16.         内容
  17.         内容
  18.       </vxe-print-page-break>
  19.       <template #footer="{ currentPage, pageCount }">
  20.         
  21.           自定义页尾,当前页码:{{ currentPage }}/{{ pageCount }}
  22.         
  23.       </template>
  24.     </vxe-print>
  25.     <vxe-button @click="printEvent1">直接打印</vxe-button>
  26.     <vxe-button @click="printEvent2">调用方法打印</vxe-button>
  27.   
  28. </template>
复制代码
分页打印表格

5.png
  1. <template>
  2.   
  3.     <vxe-button @click="printEvent">分页打印表格</vxe-button>
  4.     <vxe-table
  5.       border
  6.       height="500"
  7.       ref="tableRef"
  8.       :data="tableData">
  9.       <vxe-column field="id" title="ID" width="60"></vxe-column>
  10.       <vxe-column field="name" title="Name"></vxe-column>
  11.       <vxe-column field="sex" title="Sex"></vxe-column>
  12.       <vxe-column field="address" title="Address"></vxe-column>
  13.     </vxe-table>
  14.   
  15. </template>
复制代码
https://gitee.com/x-extends/vxe-pc-ui

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
2.png
您需要登录后才可以回帖 登录 | 立即注册