首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在vueJS上使用PrintJS打印页面节

在vueJS上使用PrintJS打印页面节
EN

Stack Overflow用户
提问于 2021-01-25 21:39:06
回答 2查看 917关注 0票数 0

我使用npm install print-js --save在我的vue项目中安装了printJS

Print Preview现在可以成功显示,但问题是它正在打印整个页面以及侧面板和滚动条。我像这样实现了它:

代码语言:javascript
复制
<template>
  <b-modal>
     <div id="print-form">
       <table style="border-collapse: collapse; width: 100%" border="1px">
       </table>
        <button onclick="print()" class="btn btn-primary btn-block">Print</button>
     </div>
  </b-modal>
</template>

import * as Printjs from "print-js";
export default {
   method: {
     print() {
       Printjs({
         printable: "print-registration-form", //Id to print content 
         type: "HTML"
      });
    }
  }
}

当我单击print时,它将打印整个页面,而不是id指定的页面部分。有没有办法只打印特定的div内容?

EN

回答 2

Stack Overflow用户

发布于 2021-01-28 04:16:42

看起来您使用了错误的id。你的意思是用print-form代替吗?

代码语言:javascript
复制
       printJS({
         printable: "print-form",
         type: "HTML"
       });
票数 2
EN

Stack Overflow用户

发布于 2021-01-25 21:43:26

我可以向你提出这个解决方案:

代码语言:javascript
复制
@media print { 
  body * { 
  visibility: hidden; 
  } 
  #targetDiv, #targetDiv * { 
  visibility: visible; border: none; 
  }
} 
代码语言:javascript
复制
 <!DOCTYPE html>
 <html> 
 <body> 
  <h2>The window.print() Method</h2> 
  <div>
    <p>Click the button to print the current page.</p> 
  </div>
  
  <div id="targetDiv">
    <p>Lorem ipsum kjng kq fev lnb fesl</p>   
  </div>
  <button onclick="window.print()">Print this page</button> 
 </body> 
 </html>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65885900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档