vue打印网页,可以局部打印

github的跳转连接

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

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了

猜你喜欢

转载自www.cnblogs.com/blog-akang/p/10687731.html
今日推荐