Vue3前端做打印頁面信息實(shí)現(xiàn)打印功能(打印界面某個(gè)部分)
一、先看效果:

二、使用的依賴:
使用的是:vue3-print-nb;
版本號"vue3-print-nb": "^0.1.4",
npm install vue3-print-nb
三、注冊使用:
下好依賴后在項(xiàng)目里的 main.js 文件里面注冊使用一下
import print from 'vue3-print-nb' app.use(print);

四、打印頁面代碼:
通過 v-print="printInfoObj" 自定義指令綁定打印的按鈕。
需要打印的區(qū)域通過使用 id="printInfo" 綁定。
完整代碼:
<template>
<el-button type="primary" v-print="printInfoObj">打印</el-button>
<!-- 需要打印的區(qū)域 -->
<div class="print_info_box" id="printInfo">
<div class="title_box">收貨人信息表</div>
<div>
<el-row class="public">
<el-col :span="12">
<span>收 貨 人:</span>
<span>張三三</span>
</el-col>
<el-col :span="12">
<span>下單日期:</span>
<span>2024-12-05 14:32:55</span>
</el-col>
</el-row>
<el-row class="public">
<el-col :span="12">
<span>收貨地址:</span>
<span>北京市-朝陽區(qū)-188號</span>
</el-col>
<el-col :span="12">
<span>訂單編號:</span>
<span>8564795214986528</span>
</el-col>
</el-row>
</div>
<table border="1" cellspacing="0" width="100%" class="tableStyle">
<tr height="60">
<td>商品</td>
<td colspan="2">規(guī)格</td>
<td>合計(jì)</td>
</tr>
<tr height="50">
<td>連衣裙</td>
<td>白色*5</td>
<td>粉色*15</td>
<td>20</td>
</tr>
<tr height="50">
<td>牛仔褲</td>
<td>黑色*13</td>
<td>藍(lán)色*19</td>
<td>32</td>
</tr>
<tr height="50">
<td>沖鋒衣</td>
<td>黑色*3</td>
<td>白色*1</td>
<td>4</td>
</tr>
<tr height="50">
<td colspan="3">總計(jì)</td>
<td>56</td>
</tr>
</table>
<div>
<el-row class="public">
<el-col :span="6">
<span>調(diào)配人:</span>
<span>________</span>
</el-col>
<el-col :span="6">
<span>核對人:</span>
<span>________</span>
</el-col>
<el-col :span="6">
<span>對接人:</span>
<span>________</span>
</el-col>
<el-col :span="6">
<span>發(fā)貨人:</span>
<span>________</span>
</el-col>
</el-row>
</div>
</div>
</template>
<script setup>
// 打印區(qū)域配置對象
const printInfoObj = {
id: "printInfo",
popTitle: "收貨人信息表", // 打印頁面的頁眉
preview: false, // 是否開啟預(yù)覽
beforeOpenCallback(vue) {
// console.log('觸發(fā)打印工具打開前回調(diào)')
vue.printLoading = true;
},
openCallback(vue) {
// console.log('觸發(fā)打印工具打開的回調(diào)')
vue.printLoading = false;
},
closeCallback() {
// console.log('觸發(fā)關(guān)閉打印工具回調(diào)')
},
previewBeforeOpenCallback() {
// console.log('觸發(fā)預(yù)覽前回調(diào)')
},
previewOpenCallback() {
// console.log('觸發(fā)預(yù)覽的回調(diào)')
},
};
</script>
<style lang="less" scoped>
// 去掉頁眉頁腳
// @page {
// size: auto;
// margin: 0mm;
// }
// 隱藏左下方頁腳URL鏈接
// @page {
// size: A4(JIS);
// margin: 10mm 18mm;
// }
.print_info_box {
padding: 25px 50px;
.title_box {
text-align: center;
font-size: 26px;
font-weight: 700;
margin-bottom: 30px;
}
.tableStyle {
font-size: 14px;
color: #000;
text-align: center;
margin-bottom: 30px;
}
.public {
margin-bottom: 15px;
}
}
</style>
五、歡迎參考:
打印的方式很多,大家選擇適合自己項(xiàng)目的即可
到此這篇關(guān)于Vue3前端做打印頁面信息實(shí)現(xiàn)打印功能的文章就介紹到這了,更多相關(guān)Vue3前端打印功能內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue開發(fā)中出現(xiàn)Loading?Chunk?Failed的問題解決
本文主要介紹了Vue開發(fā)中出現(xiàn)Loading?Chunk?Failed的問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
vue3組合式API獲取子組件屬性和方法的代碼實(shí)例
這篇文章主要為大家詳細(xì)介紹了vue3組合式API獲取子組件屬性和方法的代碼實(shí)例,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
vue項(xiàng)目中created()被調(diào)用多次的踩坑實(shí)戰(zhàn)
在vue項(xiàng)目中我在created中調(diào)用了兩次get數(shù)據(jù)請求,所以下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目中created()被調(diào)用多次的踩坑實(shí)戰(zhàn),需要的朋友可以參考下2023-03-03
vue同時(shí)使用element ui和ant design vue實(shí)現(xiàn)方式
文章總結(jié):作者在 Vue 項(xiàng)目中同時(shí)使用了 Element UI 和 Ant Design Vue,遇到了全局引入 Ant Design Vue 時(shí)的問題,解決方案是根據(jù)項(xiàng)目是 Vue2 和 Ant Design Vue 版本1.7.2,按照官方文檔正確引入,這樣可以正常啟動(dòng)項(xiàng)目并使用組件2025-12-12
Vue3.0監(jiān)聽器watch與watchEffect詳解
在 Vue 3 中,watch 仍然是一種用于監(jiān)聽數(shù)據(jù)變化并執(zhí)行相應(yīng)操作的方式,不過在組合式 API 中,watch 的使用方式與選項(xiàng)式 API 略有不同,這篇文章主要介紹了Vue3.0監(jiān)聽器watch與watchEffect,需要的朋友可以參考下2023-12-12
van-dialog彈窗異步關(guān)閉功能-校驗(yàn)表單實(shí)現(xiàn)
有時(shí)候我們需要通過彈窗去處理表單數(shù)據(jù),在原生微信小程序配合vant組件中有多種方式實(shí)現(xiàn),其中UI美觀度最高的就是通過van-dialog嵌套表單實(shí)現(xiàn),這篇文章主要介紹了van-dialog彈窗異步關(guān)閉-校驗(yàn)表單,需要的朋友可以參考下2023-11-11
基于Vue3+UniApp在單個(gè)頁面實(shí)現(xiàn)固定TabBar的多種方式
tabBar 是移動(dòng)端應(yīng)用常見的頁面效果,用于實(shí)現(xiàn)多頁面的快速切換,本文給大家介紹了如何基于Vue3+UniApp在單個(gè)頁面實(shí)現(xiàn)固定TabBar的多種方式,需要的朋友可以參考下2025-03-03

