github的跳转连接

下载print.js到本地,放入静态资源文件中,在main.js中引入: 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
import Print from './util/print'
Vue.use(Print)

在需要打印的页面直接调用就可以了

<template>
    <div ref=print>
        需要打印的内容
    </div>
    <div @click=“print”>点击打印 </div>        
</template>

<script>
   methods:{
    pritn(){
      this.$print(this.$refs.print)
   }
}
</script>

这样就可以是不是很简单

原本看他的文档是可以筛选不打印的元素,但是试了下不行

于是我就把不打印的元素在打印的时候直接隐藏

handlePrint () {
      this.showBtn = false  // 隐藏因素
      setTimeout(() => {
        this.$print(this.$refs.print)
        this.showBtn = true // 显示元素
      }, 50)
    },

这样就OK了

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄