1.0.2 • Published 9 months ago

vue3-printer v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

vue3-printer

本插件基于vue-print-next 开发,支持组件式打印和指令式打印,组件式打印支持自定义页眉页脚。

一、组件式

1. 全局

import { createApp } from "vue";
import App from "./App.vue";
import VuePrinter from "vue3-printer";

const app = createApp(App);
app.use(VuePrinter);
app.mount("#app");

2. 单个组件使用

<script setup>
  // 需要注意,这里导入的是PrintComponent,大写的P
  import {PrintComponent} from 'vue3-printer';


  const onPrintClick = ()=>{
    printComponentRef.value.print();
  }
</script>

<template>
  <div>
    <button @click="onPrintClick">打印</button>
    <print-component ref="printComponentRef">
        <template #header>
            <h1>header</h1>
        </template>
        <template #default>
              <div>
         <p>这是需要打印的局部内容</p>
         <p>更多内容...</p>
        </div>
        </template>
        <template #footer>
            <h4>footer</h4>
        </template>
    </print-component>

</template>

3. 组件 API

Props

参数类型说明默认值
printOptionsobject打印参数,详见下方printOptions-
pageMarginstring|number|string[]|number[]页边距,单位px,传数组时对应上,右,下,左的顺序30
footerobject页脚配置,详见下方footer-

printOptions

参数类型说明默认值
standardstring文档类型,默认是html5,可选 html5,loose,strict'html5'
noPrintSelectorstring[]|string打印时需要忽略的 css 选择器-
previewboolean是否启用打印预览功能false
previewTitlestring预览窗口的标题'打印预览'
previewPrintBtnLabelstring预览窗口中的打印按钮标签'打印'
extraCssstring额外的 CSS 文件路径-
extraHeadstring额外的 <head> 内容-
zIndexnumber预览窗口的 z-index20002

footer

参数类型说明默认值
isLineboolean是否展示页脚的下划线false
lineColorstring下划线的颜色(isLine为true生效)"#000"
lineWidthnumber下划线宽度(isLine为true生效)1
lineStylestring下划线的类型,支持dotted solid double dashed(isLine为true生效)"solid"

Events

事件说明回调参数
openCallback打印窗口打开时的回调-
closeCallback打印窗口关闭时的回调-
beforeOpenCallback打印窗口打开前的回调(打印预览使用)-
previewBeforeOpenCallback预览框架 iframe 加载前的回调(预览使用)-
previewOpenCallback预览框架 iframe 加载完成后的回调(预览使用)-

Slots

名称说明
default打印的内容
header页眉(只在打印时生效.)
footer页脚(旨在打印时生效)

二、指令式

vPrint 指令

API 使用方法和 vue-print-next 一致,详情参考vue-print-next

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago