其他分享
首页 > 其他分享> > vue3.0打印

vue3.0打印

作者:互联网

<template class="aa">
  <div>
    <button class="notprint" @click="printOut(printDom)">
      打 印
    </button>
    <div  ref="printDom">
      <hr />
      <hr />
        需打印的内容
      <hr />
    </div>
  </div>
</template>
<script>
import {
  reactive,
  ref,
} from "vue";
export default {
  name: "aa",
  components: {},
  setup(props) {
    const printDom = ref(null);
    const printOut = (dom) => {
      var newWindow = window.open("打印页面", "_blank");
      var docStr = dom.innerHTML
      newWindow.document.write(docStr);
      newWindow.document.close();
      newWindow.print();
      newWindow.close();
    };
    return {
      printOut,
      printDom
    };
  },
};
</script>
 
<style lang="less" scoped>
 // 隐藏不需要打印的部分
@media print {
  .notprint {
    display: none;
  }
}
</style>
————————————————
版权声明:本文为CSDN博主「Ling_a_Sir」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Ling_a_Sir/article/details/121512452

  

标签:Sir,printOut,const,打印,newWindow,vue3.0,close
来源: https://www.cnblogs.com/zjxzhj/p/16300932.html