Scene
Most background systems have the need for printing. When there is a printing requirement, it is of course easier for the front-end to print the page directly. So this article is in vue3, using the vue3-print-nb plug-in to print the area to achieve wherever you point!
1. Install vue3-print-nb
npm install vue3-print-nb
2. Introduced in
//Introduceimport print from 'vue3-print-nb' //mountconst app = createApp(App) (print)
Three.HTML
<!-- Print area container --> <div > <span>I'm the printed content</span> <span>exist#printBox container will be printed</span></div> <!-- Button binding print --> <button v-print="print">Click to open the print preview</button>
4. Parameter configuration
// Here is the printed configuration itemconst print=ref({ id: 'printBox',//The id here is the id of our printing area above, which is to click wherever we refer to popTitle: 'Configure header title', // Print the title above the configuration page extraHead: '', // The top head text, additional tags attached to the head tag, split using commas preview: false, // Whether to start preview mode, default is false previewTitle: 'Preview title', // Print the preview title previewPrintBtnLabel: 'The preview ends,Start printing', // Print the text of the button below the preview title, click to enter the print zIndex: 20002, // The z-index of the preview window is 20002 by default, preferably higher than the default value previewBeforeOpenCallback() { ('The preview window is loading! '); }, // The preview window opens before the callback previewOpenCallback() { ('The preview window has been loaded, and the preview is open! ') }, // Callback when the preview window opens beforeOpenCallback() { ('Before printing! ') }, // Start printing the callback openCallback() { ('Execute printing! ') }, // Callback when printing closeCallback() { ('Close the printing tool! ') }, // Close the printed callback (cannot distinguish between confirmation or cancellation) clickMounted() { ('Click the v-print bound button! ') }, })
Attachment: Paging printing sample code
<template> <div> <button v-print="'#a'">Print</button> <div > // Method 1 // Use div to wrap the blocks that need to be paging using css attribute page-break-after: always for paging <div style="page-break-after:always">Page 1</div> <div style="page-break-after:always">Page 2</div> </div> </div> </template> <style> // Method 2 // Use media query Set the height of body and html to auto when printing @media print { @page { size: auto; } body, html { //If vue's outermost id is, the default is #app. If height:100%; is set, then #app will also add height: auto !important; } } </style>
Summarize
This is the article about vue3 using vue3-print-nb to implement regional printing function. For more related content related to vue3 to implement regional printing, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!