vue2 vue-print-nb使用,以及使用vue-print-nb打印会多一张空白页问题解决

html

html 复制代码
    <button v-show="false" ref="printBtn" v-print="printBill">
      Print local range
    </button>

    <div id="printBill">
      <div
        v-for="(page, index) in printList"
        :key="index"
        style="page-break-after: always; border: 1px solid transparent"
      >
        <p v-if="index === 0" class="printBill-title">
          当前打印共{{ accountList.length }}条记录
        </p>
        <div v-for="item in page" :key="item.id" class="print-info">
          <p class="info-title">
            直系亲属可访问"服刑人员信息查询系统"(https://gdjyj.gd.gov.cn/fxrycx_pc/login),并在登录页面上输入查询账号及查询密码,即可查询到服刑人员在狱内的教育改造情况。
          </p>
          <div class="info-table">
            <div class="info-table-item">
              <div class="item-top">姓名</div>
              <div class="item-bottom">{{ item.name }}</div>
            </div>
            <div class="info-table-item">
              <div class="item-top">监区</div>
              <div class="item-bottom">{{ item.prisonRoom }}</div>
            </div>
            <div class="info-table-item">
              <div class="item-top">查询账号</div>
              <div class="item-bottom">{{ item.account }}</div>
            </div>
            <div class="info-table-item">
              <div class="item-top">密码修改</div>
              <div class="item-bottom">{{ item.password }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>

js

javascript 复制代码
  export default {
    name: 'Offender',
    components: {},
    data() {
        // 打印配置
        printBill: {
          id: 'printBill',
          popTitle: '你好啊', // 打印配置页上方标题
          extraHead: '', //最上方的头部文字,附加在head标签上的额外标签,使用逗号分隔
          preview: '', // 是否启动预览模式,默认是false(开启预览模式,可以先预览后打印)
          previewTitle: '', // 打印预览的标题(开启预览模式后出现),
          previewPrintBtnLabel: '', // 打印预览的标题的下方按钮文本,点击可进入打印(开启预览模式后出现)
          zIndex: '', // 预览的窗口的z-index,默认是 20002(此值要高一些,这涉及到预览模式是否显示在最上面)
          clickMounted() {},
          previewBeforeOpenCallback(vue) {
            //预览窗口打开之前的callback(开启预览模式调用)
            console.log('正在加载预览窗口')
          },
          previewOpenCallback(vue) {
            // 预览窗口打开之后的callback(开启预览模式调用)
            console.log('已经加载完预览窗口')
          },
          beforeOpenCallback(vue) {
            console.log('打开之前')
          },
          openCallback(vue) {
            console.log('执行了打印')
          },
          closeCallback() {
            this.printList = []
            that.closeCallbackHandle()
            // console.log('关闭打印')
            // that.updateStatusHandle()
            // that.printList = []
            // that.accountList = []
            // if (that.dialogVisiblePrint) {
            //   that.printClose()
            // }
          }, //关闭打印的回调事件(无法确定点击的是确认还是取消)
        },
      }
    },
    created() {},
    methods: {
      printListDivision(list) {
        // let list = [1,2,3,4,5,6,7,8,9,10,11]
        let step = 8
        let arr = []
        for (let i = 0; i < list.length; i += step) {
          if (i + step <= list.length) {
            arr.push(list.slice(i, i + step))
          } else {
            arr.push(list.slice(i))
          }
        }
        console.log(arr)
        return arr
      },
      async handlePrint(id) {
        const { value } = await printAccount({
          ids: id,
        })
        if (!value.length) {
          this.$message.warning('暂无数据打印')
          return
        }
        this.accountList = value
        this.printList = this.printListDivision(value)
        this.$refs.printBtn.click()
      },
    },
  }

使用vue-print-nb打印会多一张空白页问题解决

div上加上样式border: 1px solid transparent

css 复制代码
border: 1px solid transparent
相关推荐
WooaiJava1 小时前
AI 智能助手项目面试技术要点总结(前端部分)
javascript·大模型·html5
LYFlied1 小时前
从 Vue 到 React,再到 React Native:资深前端开发者的平滑过渡指南
vue.js·react native·react.js
爱喝白开水a1 小时前
前端AI自动化测试:brower-use调研让大模型帮你做网页交互与测试
前端·人工智能·大模型·prompt·交互·agent·rag
Never_Satisfied2 小时前
在JavaScript / HTML中,关于querySelectorAll方法
开发语言·javascript·html
董世昌412 小时前
深度解析ES6 Set与Map:相同点、核心差异及实战选型
前端·javascript·es6
B站_计算机毕业设计之家2 小时前
豆瓣电影数据采集分析推荐系统 | Python Vue Flask框架 LSTM Echarts多技术融合开发 毕业设计源码 计算机
vue.js·python·机器学习·flask·echarts·lstm·推荐算法
WeiXiao_Hyy2 小时前
成为 Top 1% 的工程师
java·开发语言·javascript·经验分享·后端
吃杠碰小鸡3 小时前
高中数学-数列-导数证明
前端·数学·算法
kingwebo'sZone3 小时前
C#使用Aspose.Words把 word转成图片
前端·c#·word
xjt_09013 小时前
基于 Vue 3 构建企业级 Web Components 组件库
前端·javascript·vue.js