vue项目打印网页功能-vue-print-nb

<button v-print>Print the entire page</button>

描述:

支持两种打印方式,直接打印页面 HTML、打印 URL

简单易用,支持兼容 Vue 的浏览器版本

在线Demo:

 测试DEMO地址

安装:

Vue2 版本

npm install vue-print-nb --save

Vue3 版本

npm install vue3-print-nb --save

 v-print API

使用方法

打印整个页面:

<button v-print>Print the entire page</button>

打印指定范围:

<button v-print="printObj">Print local range</button>
export default {
    data() {
        return {
            printObj: {
              url: 'http://localhost:8080/'
              beforeOpenCallback (vue) {
                console.log('打开之前')
              },
              openCallback (vue) {
                console.log('执行了打印')
              },
              closeCallback (vue) {
                console.log('关闭了打印工具')
              }
            }
        };
    }
}

打印网址:

<button v-print="printObj">Print local range</button>
export default {
    data() {
        return {
            printObj: {
              url: 'http://localhost:8080/'
              beforeOpenCallback (vue) {
                console.log('打开之前')
              },
              openCallback (vue) {
                console.log('执行了打印')
              },
              closeCallback (vue) {
                console.log('关闭了打印工具')
              }
            }
        };
    }
}

打印预览

支持打印预览、传入、支持所有打印方式preview:true

打印网址预览:
<button v-print="printObj">Print local range</button>
export default {
    data() {
        return {
            
            printObj: {
              url: 'http://localhost:8080/'
              preview: true,
              previewTitle: 'Test Title', // The title of the preview window. The default is 打印预览
              previewBeforeOpenCallback (vue) {
                console.log('正在加载预览窗口')
              },
              previewOpenCallback (vue) {
                console.log('已经加载完预览窗口')
              },
              beforeOpenCallback (vue) {
                console.log('打开之前')
              },
              openCallback (vue) {
                console.log('执行了打印')
              },
              closeCallback (vue) {
                console.log('关闭了打印工具')
              }
            }
        };
    }
}

v-print API

ParameExplainTypeOptionalValueDefaultValue
id范围打印 ID,所需值String
standard文档类型(仅限打印本地范围)Stringhtml5/loose/stricthtml5
extraHead<head></head>在节点中添加 DOM 节点,并用(仅打印本地范围)分隔多个节点,String
extraCss<link>新的CSS样式表,并用(仅打印本地范围)分隔多个节点,String-
popTitle<title></title>标签内容(仅打印本地范围)String-
openCallback调用打印工具的成功回调函数FunctionReturns the instance of called at that timeVue-
closeCallback关闭打印工具成功的回调函数FunctionReturns the instance of called at that timeVue-
beforeOpenCallback调用打印工具前的回调函数FunctionReturns the instance of called at that timeVue-
url打印指定的 URL。(不允许同时设置ID)string--
asyncUrl通过 'resolve()' 和 Vue 返回 URLFunction--
preview预览工具Boolean-false
previewTitle预览工具标题String-'打印预览'
previewPrintBtnLabel预览工具按钮的名称String-'打印'
zIndex预览工具CSS:z-indexString,Number-20002
previewBeforeOpenCallback启动预览工具前的回调函数FunctionReturns the instance of Vue-
previewOpenCallback完全打开预览工具后的回调函数FunctionReturns the instance of Vue-
clickMounted点击打印按钮的回调功能FunctionReturns the instance of Vue-
  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值