vue3-print-nb實現(xiàn)頁面打印(含分頁打印)示例代碼
安裝vue3-print-nb
npm install vue3-print-nb --save
引用vue3-print-nb
全局引入
// 全局引用 import { createApp } from 'vue' import App from './App.vue' import print from 'vue3-print-nb' const app = createApp(App) app.use(print) app.mount('#app')
局部引入
// 單組件引用 import print from 'vue3-print-nb' // 在自定義指令中注冊 directives: { print }
API
官網(wǎng)地址:https://github.com/Power-kxLee/vue3-print-nb
官網(wǎng)有詳細(xì)介紹
示例代碼
全頁面打印
<button v-print>打印整個頁面</button>
局部打印
被打印的區(qū)域需要被渲染出來,隱藏的元素不能打印
<div id="a"> <p>打印我吧</p> <p>打印我吧</p> <p>打印我吧</p> </div> //寫法一 <button v-print="#a">局部打印</button> //寫法二(可以接受對象) <button v-print="{id:a}">局部打印</button>
分頁打印
<template> <div> <button v-print="'#a'">打印</button> <div id="a"> // 方法一 // 使用div包裹需要分頁的塊 使用 css屬性 page-break-after:always進(jìn)行分頁 <div style="page-break-after:always">第一頁</div> <div style="page-break-after:always">第二頁</div> </div> </div> </template> <style> // 方法二 // 使用媒體查詢 在打印時設(shè)置 body 和 html 的高度為auto @media print { @page { size: auto; } body, html { //如果vue最外層id,默認(rèn)是#app。如果設(shè)置了height:100%;,那么#app也加 height: auto !important; } } </style>
總結(jié)
到此這篇關(guān)于vue3-print-nb實現(xiàn)頁面打印(含分頁打印)的文章就介紹到這了,更多相關(guān)vue3-print-nb實現(xiàn)頁面打印內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
flutter使用tauri實現(xiàn)一個一鍵視頻轉(zhuǎn)4K軟件
這篇文章主要為大家介紹了flutter使用tauri實現(xiàn)一個一鍵視頻轉(zhuǎn)4K軟件詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09使用element-ui +Vue 解決 table 里包含表單驗證的問題
這篇文章主要介紹了使用element-ui +Vue 解決 table 里包含表單驗證的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue實戰(zhàn)之vue登錄驗證的實現(xiàn)代碼
本篇文章主要介紹了Vue實戰(zhàn)之vue登錄的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10Vue用v-for給循環(huán)標(biāo)簽自身屬性添加屬性值的方法
這篇文章主要介紹了Vue用v-for給循環(huán)標(biāo)簽自身屬性添加屬性值的方法,文中大家給大家列舉了三種方法 ,需要的朋友可以參考下2018-10-10Vue使用watch監(jiān)聽一個對象中的屬性的實現(xiàn)方法
這篇文章主要介紹了Vue使用watch監(jiān)聽一個對象中的屬性的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05