您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

vue实现打印功能的两种方法(附代码)

2024/12/5 1:26:28发布21次查看
本篇文章给大家带来的内容是关于vue实现打印功能的两种方法(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
第一种方法:通过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'}) // 使用
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注的javascript教程视频栏目!
以上就是vue实现打印功能的两种方法(附代码)的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product