vue实现打印功效的两种办法(附代码)
发布时间:09/01 来源:未知 浏览:
关键词:
第一种办法:通过npm 安置插件
1,安置 npm install vue-print-nb --save
2,引入 安置好今后在main.js文件中引入
import Print from 'vue-print-nb' Vue.use(Print); //注册
3,此刻就可以使用了
<div id="printTest" > <p>明月照于山间</p> <p>清风来于江上 </p> </div> <button v-print="'#printTest'">打印</button>
4.如需通过链接地址打印:window.location.href = airway_bill; airway_bill为链接地址。
5.假如内容打印不全,在打印操纵时点击更多设定,然后设定缩放。
第二种办法:手动下载插件到当地
插件地址:https://github.com/xyl66/vuePlugs_printjs
1.在src下创建文件夹plugs,将下载好的print.js放入plugs文件夹下,然后操纵如下
import Print from '@/plugs/print' Vue.use(Print) // 注册 <template> <section ref="print"> 打印内容 <div class="no-print">不要打印我</div> </section> </template> this.$print(this.$refs.print) // 使用
2.留意事项 需使用ref猎取dom节点,若直接通过id或class猎取则webpack打包摆设后打印内容为空
3.指定不打印区域
办法1. 增加no-print样式类
<div class="no-print">不要打印我</div>
办法2. 自定义类名
<div class="do-not-print-me-xxx">不要打印我</div> this.$print(this.$refs.print,{'no-print':'.do-not-print-me-xxx'}) // 使用
本篇文章到这里就已经全部完毕了,更多其他出色内容可以关注PHP中文网的JavaScript教程视频栏目!
以上就是vue实现打印功效的两种办法(附代码)的具体内容,更多请关注百分百源码网其它相关文章!