Tips: 本文针对在vue3的项目使用介绍

1、安装插件

首先,通过 npm 安装 vue3-print-nb

npm install vue3-print-nb --save
2、全局引用

在 vue3项目的 main.js 文件中导入使用

import print from 'vue3-print-nb';

.vueApp.use(print);
3、组件使用

在任一组件中执行以下步骤方法

定义打印区域


<template>
    <a-card>
      // 2.绑定打印按钮(注意绑定按钮时是:'#printArea',有单引号)
      <template #extra>
        <a-button v-print="'#printArea'">普通打印</a-button>
      </template>
	  // 1.定义打印区域
      <section ref="print" id="printArea">
          /** 打印区域*/
      </section>
	</card>
</template>

<script setup>
    import { ref, vue } from 'vue';
    // 3.定义打印变量
    const print = ref(false);
</script>
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐