vue打印插件vue-print-nb的实现代码

 更新时间:2022年03月17日 10:26:16   作者:你猜我为啥秃头  
这篇文章主要介绍了vue打印插件vue-print-nb的实现,需要引入插件npm install vue-print-nb --save,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

1.引入插件npm install vue-print-nb --save

在main.js中引入

import Print from 'vue-print-nb'Vue.use(Print)

2.html代码

<div class="box">
    <div id="printTest" class="upTable">
      <table>
        <tr>
          <td class="title" colspan="4">木材检尺报告书</td>
        </tr>
        <tr>
          <td class="one">船名</td>
          <td style="width:190px">{{ goods.shipName }}</td>
          <td class="one">输出国</td>
          <td>{{ goods.exportCountry }}</td>
        </tr>
        <tr>
          <td class="one">树种</td>
          <td>{{ variety }}</td>
          <td class="one">委托方/货主</td>
          <td>{{ goods.goodsMaster }}</td>
        </tr>
        <tr>
          <td class="one">申报材积</td>
          <td>{{ goods.declareWoodVolume }}立方米</td>
          <td class="one">申报数量</td>
          <td>{{ goods.declareNumber }}根</td>
        </tr>
        <tr>
          <td class="one">存放地点</td>
          <td>{{ goods.goodsYard }}</td>
          <td class="one">卸毕时间</td>
          <td v-if="goods.unloadTime">{{ goods.unloadTime.substring(0,10) }}</td>
          <td v-else />
        </tr>
        <tr>
          <td class="one">检验标准</td>
          <td colspan="3">GB/T 144-2013 国家标准</td>
        </tr>
        <tr>
          <td class="title2" colspan="4">检验结果</td>
        </tr>
      </table>
      <table class="dataTable">
        <tr>
          <td style="width:210px">垛位号</td>
          <td style="width:100px">长度</td>
          <td style="width:100px">已检整木</td>
          <td style="width:100px">材积</td>
          <td style="width:100px">断木</td>
          <td style="width:0">未检整木</td>
        </tr>
        <tr v-for="(item,index) in shortData" :key="index">
          <td>{{ item.placeNumber }}</td>
          <td>{{ item.placeLength }}</td>
          <td>{{ item.zs }}</td>
          <td>{{ item.woodVolume }}</td>
          <td>{{ item.damagedWood }}</td>
          <td>{{ item.notCheckWood }}</td>
        </tr>
        <tr>
          <td style="width:210px">合计</td>
          <td style="width:100px" />
          <td style="width:100px">{{ zsAll }}</td>
          <td style="width:100px">{{ woodVolumeAll }}</td>
          <td style="width:100px">{{ damagedWoodAll }}</td>
          <td style="width:0px">{{ notCheckWoodAll }}</td>
        </tr>
      </table>
    </div>
    <el-button v-print="'#printTest'" type="primary" style="margin-top:20px">
      打印
    </el-button>
  </div>

3.js代码

<script>
export default {
  props: ['catList', 'goods'],
  data() {
    return {
    //和下边 <style media="printTest"> 一起的作用是去掉页眉页脚、去掉多出空白页的问题
      printObj: {
        id: 'printTest',
        popTitle: '',
        ectraHead: ''
      },
      shortData: [],
      variety: '',
      zsAll: 0, // 已检整木  总数
      woodVolumeAll: 0, // 材积
      damagedWoodAll: 0, // 断木
      notCheckWoodAll: 0, // 未检整木
      updateTime: ''
    }
  },
  methods: {
  //这里的数据是在父页面传来的
    getvariety(variety, catList, goods) {
      this.variety = variety
      this.shortData = catListthis.goods = goods// 合计
      let zsAll = 0
      let woodVolumeAll = 0
      let damagedWoodAll = 0
      let notCheckWoodAll = 0
      this.shortData.map((item) => {
        zsAll += item.zs
        woodVolumeAll += item.woodVolume
        damagedWoodAll += item.damagedWood
        notCheckWoodAll += item.notCheckWood
      })
      this.zsAll = zsAll
      this.woodVolumeAll = woodVolumeAll
      this.damagedWoodAll = damagedWoodAll
      this.notCheckWoodAll = notCheckWoodAll
    },
  }
}
</script>

4.样式

<style media="printTest">
@page {
    size: auto;
    margin: 3mm;
  }

  html {
    background-color: #ffffff;
    height: auto;
    margin: 0px;
  body {
    border: solid 1px #ffffff;
    margin: 10mm 15mm 10mm 15mm;
</style>
<style lang="less" scoped>
.upTable{
    width: 100%;
    height: 50%;
    margin-top: 10px;
    table{
        width: 100%;
        border-collapse:collapse
    }
    td{
        border: 1px solid #000;
        font-size: 18px;
        text-align: center;
        font-family: Source Han Sans CN;
        font-weight: 450;
        color: #000000;
    .title{
        font-size: 20px;
        height: 50px;
        font-weight: 550;
    .one{
        width: 20%;
        height: 40px;
    .title2{
        height: 45px;
    .dataTable{
        border-top: 0px solid #000000;
        td{
            //  border: 1px solid #000;
            font-size: 18px;
            text-align: center;
            font-family: Source Han Sans CN;
            font-weight: 450;
            color: #000000;
            padding: 5px 0;
        }
}
.el-button{
    margin-right: 20px;
    margin-left: 20px;
    width: 100px;
    padding: 12px 0;

到此这篇关于vue打印插件vue-print-nb的实现的文章就介绍到这了,更多相关vue打印插件vue-print-nb内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 解决vue router使用 history 模式刷新后404问题

    解决vue router使用 history 模式刷新后404问题

    这篇文章主要介绍了解决vue router使用 history 模式刷新后404问题,需要的朋友可以参考下
    2017-07-07
  • Vue.js特性Scoped Slots的浅析

    Vue.js特性Scoped Slots的浅析

    这篇文章主要介绍了Vue.js特性Scoped Slots的浅析,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-02-02
  • vue跳转页签传参并查询参数的保姆级教程

    vue跳转页签传参并查询参数的保姆级教程

    这篇文章主要介绍了vue跳转页签传参并查询参数的保姆级教程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • 关于vue中@click.native.prevent的说明

    关于vue中@click.native.prevent的说明

    这篇文章主要介绍了关于vue中@click.native.prevent的说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-03-03
  • Vue3中事件总线的具体使用

    Vue3中事件总线的具体使用

    本文主要介绍了Vue3中事件总线的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04
  • vue使用原生swiper代码实例

    vue使用原生swiper代码实例

    这篇文章主要介绍了vue使用原生swiper代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-02-02
  • 详解Vue3中ref和reactive函数的使用

    详解Vue3中ref和reactive函数的使用

    这篇文章主要为大家详细介绍了Vue3中ref和reactive函数的使用教程,文中的示例代码讲解详细,对我们学习Vue有一定的帮助,需要的可以参考一下
    2022-07-07
  • 谈谈我在vue-cli3中用预渲染遇到的坑

    谈谈我在vue-cli3中用预渲染遇到的坑

    这篇文章主要介绍了谈谈我在vue-cli3中用预渲染遇到的坑,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04
  • 浅析vue-router jquery和params传参(接收参数)$router $route的区别

    浅析vue-router jquery和params传参(接收参数)$router $route的区别

    今天做项目时踩到了vue-router传参的坑(jquery和params),所以决定总结一下二者的区别。感兴趣的朋友跟随脚本之家小编一起看看吧
    2018-08-08
  • vue父组件监听子组件数据更新方式(hook)

    vue父组件监听子组件数据更新方式(hook)

    这篇文章主要介绍了vue父组件监听子组件数据更新方式(hook),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-08-08

最新评论