简体   繁体   中英

How to apply styles and css and bootstrap cdn in window.print() when using vuejs?

I want get Print From my component in Vuejs.

Also I want apply my css and bootsrap in window.print()

I use window.print() in mounted Like this:

       export default {
             mounted() {        
                  window.print();

               }
          }

But CSS and Bootstrap have not been applied to the print screen.

Can you tell me how to fix it?

UPDATE : I use adminlte Template.It may be a problem

Hi you can have two ways to achieve this

PrintScreen(el)
{
    let printWindow = window.open('', 'PRINT', 'height=600,width=800');

    printWindow.document.write('<html><head><title>' + document.title  + '</title>');
    printWindow.document.write('</head><body >');
    printWindow.document.write('<h1>' + document.title  + '</h1>');
    printWindow.document.write(document.getElementById(el).innerHTML);
    printWindow.document.write('</body></html>');

    printWindow.document.close(); // IE >= 10
    printWindow.focus(); //  IE >= 10*/

    printWindow.print();
    printWindow.close();

    return true;
}

Or

You can use a wrapper to do this stuff Npm Link

npm install vue-html-to-paper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM