使用vue-plugin-hiprint实现打印功能

1.效果图

在这里插入图片描述

2.安装
  1. 插件安装
npm i vue-plugin-hiprint
  1. 引入样式
    复制一份hiprint/css/print-lock.css文件到public中,在index.html中引入
<!-- 防止打印不正常 -->
<link rel="stylesheet" type="text/css" media="print" href="<%= BASE_URL %>print-lock.css" />
3.引入插件
  1. 全局引入
// main.ts
import {
   
    hiPrintPlugin } from 'vue-plugin-hiprint'
app.use(hiPrintPlugin)
  1. 局部引入
// 需要使用的的文件中
import {
   
    hiPrintPlugin } from 'vue-plugin-hiprint'
4.完整代码
<template>
  <div class="pageIndex">
    <div class="topBtnBox">
      <div class="paper">
        <!-- 纸张大小 A3、A4 等 -->
        <!-- <template> -->
        <button v-for="(value, type) in paperSize" :key="type" @click="setPaper(type, value)">
          {
  
  { type }}
        </button>
        <!-- </template> -->
        <!-- 自定义纸张 -->
        <button @click="paperPopVisible = !paperPopVisible">自定义纸张</button>
        <!-- 自定义纸张 popover -->
        <div class="popover">
          <div class="popover-content" v-show="paperPopVisible">
            <!-- <div style="font-size: 16px; font-weight: bold">
              设置纸张宽高(mm)
            </div> -->
            <div>
              <input class="input" v-model="paperWidth" type="number" placeholder="宽(mm)" />
              <span>x</span>
              <input class="input" v-model="paperHeight" type="number" placeholder="高(mm)" />
            </div>
            <button @click.stop="setPaperOther">确定</button>
          </div>
        </div>
        <button @click="changeScale('+')">+</button>
        <button @click="changeScale('-')">-</button>
        <input v-model="scaleValue" disabled style="width: 40px; text-align: center" />
        <button @click="changeScale(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值