vue vxe-print 实现纯 web H5 打印功能,不需要额外安装浏览器插件,纯浏览器 Web 打印
官网:https://vxeui.com/
https://github.com/x-extends/vxe-pc-ui
安装
npm install vxe-pc-ui@4.3.22 vxe-table@4.9.19
// ...
import VxeUI from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'
// ...
createApp(App).use(VxeUI).use(VxeUITable).mount('#app')
// ...
打印图片

<template>
<div>
<vxe-print ref="printRef" custom-layout>
<img src="https://vxeui.com/resource/img/invoice345.png" style="width: 100%;">
</vxe-print>
<vxe-button @click="printEvent1">直接打印</vxe-button>
<vxe-button @click="printEvent2">调用方法打印</vxe-button>
</div>
</template>
<script setup>
import {
ref } from 'vue'
import {
VxeUI } from 'vxe-pc-ui'
const printRef = ref()
const printEvent1 = () => {
const $print = printRef.value
if ($print) {
$print.print()
}
}
const printEvent2 = () => {
VxeUI.print({
html: `
<img src="https://vxeui.com/resource/img/invoice345.png" style="width: 100%;">
`
})
}
</script>
自定义页眉

<template>
<div>
<vxe-print ref="printRef">
<template #header>
<div style="
2221




被折叠的 条评论
为什么被折叠?



