美文网首页
vue实现打印功能

vue实现打印功能

作者: 莫伊剑客 | 来源:发表于2022-01-24 16:03 被阅读0次

打印功能可以自己使用原生js(window.print())实现,其次就是使用插件,介绍一个打印插件

vue-print-nb:这个插件使用起来还是很便捷的,用法如下
1、安装

// vue2.0
npm install vue-print-nb --save
// vue3.0
npm install vue3-print-nb --save

请根据自己的需求安装版本

2、配置
vue2.0

// 全局配置
import Print from 'vue-print-nb'
Vue.use(Print);

// 仅使用页面配置
import print from 'vue-print-nb'
directives: {
    print   
}

vue3.0

// 全局配置
import print from 'vue3-print-nb'
const app = createApp(App)
app.use(print)

// 仅使用页面配置
import print from 'vue3-print-nb'
directives: {
    print   
}

3、具体使用方法:(1)直接绑定id方法 (2)绑定对象方法

<!--直接绑定id方法-->
<div id='box'>
   <p>打印内容</p>
   <p>打印内容1111</p>
</div>
<div v-print="'#box'">打印</div>

<!--直接绑定对象方法-->
<div id='box'>
   <p>打印内容</p>
   <p>打印内容1111</p>
</div>
<div v-print='printObj'>打印</div>

export default{
   data(){
      return {
         printObj:{
            id:'box',
            beforeOpenCallback (vue) {
                console.log('打开之前')
            },
            openCallback (vue) {
                console.log('执行了打印')
            },
            closeCallback (vue) {
                console.log('关闭了打印工具')
            }
            //其他配置项,
         }
      }
   }
}

4、v-print API

Parame Explain Type OptionalValue DefaultValue
id id,required String
standard Document type (Print local range only) String html5/loose/strict html5
extraHead <head></head>Add DOM nodes in the node, and separate multiple nodes with (Print local range only), String
extraCss <link> New CSS style sheet , and separate multiple nodes with (Print local range only), String
popTitle <title></title> Content of label (Print local range only) String
openCallback Call the successful callback function of the printing tool Function Returns the instance of called at that timeVue
closeCallback Close the callback function of printing tool success Function Returns the instance of called at that timeVue
beforeOpenCallback Callback function before calling printing tool Function Returns the instance of called at that timeVue
url Print the specified URL. (It is not allowed to set the ID at the same time) String
asyncUrl Return URL through 'resolve()' and Vue Function
preview Preview tool Boolean false
previewTitle Preview tool Title String '打印预览'
previewPrintBtnLabel The name of the preview tool button String '打印'
zIndex CSS of preview tool: z-index String,Number 20002
previewBeforeOpenCallback Callback function before starting preview tool Function Returns the instance of Vue
previewOpenCallback Callback function after fully opening preview tool Function Returns the instance of Vue
clickMounted Click the callback function of the print button Function Returns the instance of Vue

相关文章

  • vue 实现打印功能

    1.安装插件 2.在main.js中引用 3.在页面中使用

  • vue实现打印功能

    打印功能可以自己使用原生js(window.print())实现,其次就是使用插件,介绍一个打印插件 vue-pr...

  • 前端vue项目实现单页打印功能

    前端vue项目实现单页打印功能 vue-print-nb插件:这是用于打印,简单,快速,方便,轻便的指令包装。安装...

  • VUE框架下搭建在线Excel应用

    本项目实现功能:VUE框架中 嵌入表格控件SpreadJS,实现导入Excel、导出Excel、导出PDF、打印表...

  • vue项目实现打印功能

    使用的一个叫做“vue-print-nb”的插件,具体步骤: 1 下载插件 2 在main导入并注册 3 在vue...

  • VUE 打印

    vue实现打印功能的两种方法[https://blog.csdn.net/peiyongwei/article/d...

  • vue实现打印功能(包括分页)

    最近项目中碰到一个需求,需要前端预览打印当前页面的表格,而且表格是动态渲染的,所以在打印的时候需要分页打印。 1....

  • vue实现打印入库单功能

    效果如下: 【引入的插件】import * as LodopFuncs from '@/common/LodopF...

  • vue实现打印机功能

    第一种方法:通过npm 安装插件 1,安装 2,引入 安装好以后在main.js文件中引入 3,现在就可以使用了...

  • 【vue学习】整合Lodop

    前端实现自动打印 批量打印 vue中使用lodop调用标签打印机 利用lodop打印控件轻松实现批量打印 本文主要...

网友评论

      本文标题:vue实现打印功能

      本文链接:https://www.haomeiwen.com/subject/bipbhrtx.html