Method 1: Install the plugin via npm1. Install npm install vue-print-nb --save 2. After installation, import it into the main.js file import Print from 'vue-print-nb' Vue.use(Print); //Register 3. Now you can use it <div id="printTest" > <p>The moon shines on the mountains</p> <p>The breeze comes from the river</p> </div> <button v-print="'#printTest'">Print</button> 4. To print via the link address: window.location.href = airway_bill; airway_bill is the link address. 5. If the content is not printed completely, click More Settings during the print operation, and then set the zoom. The second method: manually download the plug-in to the localPlugin address:
1. Create a new folder plugs under src, put the downloaded print.js into the plugs folder, and then do the following import Print from '@/plugs/print' Vue.use(Print) // Register <template> <section ref="print"> Print content <div class="no-print">Don't print me</div> </section> </template> this.$print(this.$refs.print) // Usage 2. Note: You need to use ref to get the DOM node. If you get it directly by id or class, the printed content will be empty after webpack packaging and deployment. 3. Specify the non-printing area Method 1. Add no-print style class <div class="no-print">Don't print me</div> Method 2. Custom class name <div class="do-not-print-me-xxx">Don't print me</div>this.$print(this.$refs.print,{'no-print':'.do-not-print-me-xxx'}) // Use Batch PrintingBatch printing here actually uses pure js writing, let's go directly to the code: <template> <div> <ul class="print-ul"> <li v-for="(item,index) of tableData" :key="index" :id="'printDiv' + index" style="page-break-after:always;"> <div> <p>{{item.date}}</p> <p>{{item.name}}</p> <p>{{item.province}}</p> <p>{{item.city}}</p> <p>{{item.address}}</p> <p>{{item.zip}}</p> </div> </li> </ul> <div @click="handlePrint">Print</div> </div> </template> <script> export default { data() { return { tableData: [{ date: '2016-05-03', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-02', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-04', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-01', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-08', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-06', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }, { date: '2016-05-07', name: 'Wang Xiaohu', province: 'Shanghai', city: 'Putuo District', address: 'No. 1518, Jinshajiang Road, Putuo District, Shanghai', zip: 200333 }] } }, methods: { handlePrint() { var newWin = window.open(""); //Open a new empty window for (var i = 0; i < this.tableData.length; i++) { var imageToPrint = document.getElementById("printDiv" + i); //Get the content to be printed newWin.document.write(imageToPrint.outerHTML); //Add the content to be printed to the new window} const styleSheet = `<style>li{list-style:none}</style>`; newWin.document.head.innerHTML = styleSheet; //Add style to the printed content newWin.document.close(); //This sentence must be added when used in IE browser newWin.focus(); //This sentence must be added when used in IE browser setTimeout(function() { newWin.print(); //Print newWin.close(); //Close the window }, 100); } } } </script> <style> .print-ul { width: 600px; list-style: none; border: 1px solid #e8e8e8; } </style> SummarizeThis is the end of this article about the implementation of vue printing function. For more relevant vue printing function content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Solution to the problem of installing MySQL compressed version zip
>>: How to completely delete the MySQL service (clean the registry)
In this article we assume you already know the ba...
This article shares the specific code of Vue+ssh ...
This article shares the specific code of Vue to i...
If you want the path following the domain name to...
1 Implementation Principle This is done using the...
The establishment of MySQL index is very importan...
<br />First of all, I have to state that I a...
Table of contents mysql permission control Permis...
In Black Duck's 2017 open source survey, 77% ...
Question 1 solve Start the service: service mysql...
Configure web page compression to save resources ...
I remember a question the interviewer asked durin...
Table of contents 1. Commonly used string functio...
A cool JavaScript code to unfollow Weibo users in...
Table of contents About Triggers Use of triggers ...