vue2踩坑之项目:生成二维码使用vue-print-nb打印二维码

news/2024/7/10 22:53:47 标签: vue.js, 前端, javascript, elementui, es6, css3

1.

vue2安装 npm install vue-print-nb --save

vue3安装 npm install vue3-print-nb --save

 2.

//vue2 引入方式 全局 main.js

import Print from 'vue-print-nb'

Vue.use(Print)

------------------------------------------------------------------------------------

//vue2 引入方式 按需

import print from 'vue-print-nb'

directives: { print} //自定义指令中注册

------------------------------------------------------------------------------------

//vue3 引入方式 全局 main.js

import { createApp } from 'vue'

import App from './App.vue'

import print from 'vue3-print-nb'

const app = createApp(App)app.use(print)app.mount('#app')

------------------------------------------------------------------------------------

//vue3 引入方式 按需

import print from 'vue3-print-nb'

directives: { print } //自定义指令中注册 

javascript">//html
   <el-button @click="clickPrint(form)">打印</el-button>

   <el-drawer 
     title="图片打印" 
     :visible.sync="drawer" 
     :direction="direction" 
     :before-close="handleClose" 
     size="80%">
      <div style="position: absolute;right: 110px;top: 15px;padding-left: 30px;">
        <!-- <el-button @click="drawer = false">取消</el-button> -->
        <el-button type="primary" v-print="print">打印</el-button>
      </div>
      
       <div id="printView">
         <div class="img-content-first" 
             :class=" index >= 5?'img-content':'img-content-first'" 
             v-for="(item,index) in erwmList" 
             :key="index">

             <img :src=item.imgBase class="img" />

           <div class="text">{{ item.connectorCode }}</div>
         </div>
       </div>

    </el-drawer>

//script
// 单组件引用打印插件
import print from 'vue-print-nb'
import {getxxxx} from "../../api/xxxx/xxxx.js" // 二维码接口


//data
// 抽屉 批量打印
data() {
 return {
    //表单筛选条件
    form:{
     status:'',
     name:'',
     //....
    },
    drawer: false,
    direction: 'rtl',
    erwmList:[], //二维码列表
    erweimaImg: '',
    // 打印插件
    print: {
    id: "printView", //打印的区域的id名
    popTitle: "管理平台", // 打印配置页上方标题
    extraHead: "", //最上方的头部文字,附加在head标签上的额外标签,使用逗号分隔
    extraCss: "",
    },
  }
}

//js
 // 批量打印 点击事件 
      clickPrint (item) {
        // console.log(item,'ss');
        if (
        (item.status=== "" || null || undefined) &&
        (item.name === ""||null||undefined)
           ) 
        {
          this.drawer = false
          this.$alert('', '请选择筛选条件!', {
          confirmButtonText: '确定',
         });
          
        } else {
              getxxxx(item).then(res => {
                  //console.log(res);
                  this.erwmList= res
              if (res) {
                this.drawer = true
               }
             })
          }
      },
      // 批量打印 抽屉关闭事件
        handleClose (done) {
          this.drawer = false
        // this.$confirm('确认关闭?')
        //   .then(_ => {
        //     done();
        //   })
        //   .catch(_ => {});
      },


//css
<style scoped lang="less">
......
  .img-content-first{
    display: inline-block;
    border: 2px solid #000;
    margin: 0 0 0 30px;

    .text{
      margin: 0 auto;
      text-align: center;
      color: #000;
      font-size: 18px;
      margin-top: -24px;
    }
  }
  .img-content{
    display: inline-block;
    border: 2px solid #000;
    margin: 50px 0 0 30px;

   .text{
      margin: 0 auto;
      text-align: center;
      color: #000;
      font-size: 18px;
      margin-top: -24px;
    }
  }
  // @media print {
  //   #print .img-content {
  //     width: 150px;
  //     height: 150px;
  // }
  // }
</style>

<!-- 添加独立style标签 -->
<style media="print" lang="less">
  @page {
    size: auto;
   
  }
  @media print {
    // html {
    //   zoom: 70%; //设置打印页面的缩放,大小
    //    margin: 0 auto;
    // }
   #printView .img-content-first{
      border: 2px solid #000;
      // width: 190px;
      height: 185px;
      margin: 10px 0 0 15px;
    }

   #printView .img-content{
      border: 2px solid #000;
      // width: 190px;
      height: 185px;
      margin: 30px 0 0 15px;
    }

   #printView .img{
      // width: 190px;
      height: 180px;
    }

   #printView .text{
      margin: 0 auto;
      text-align: center;
      color: #000;
      font-size: 18px;
      margin-top: -24px;
 }
}

上一篇文章,

vue2踩坑之项目:yarn无法加载文件 C:UsersAdministratorAppDataRoaming pmyarn.ps1,因为在此系统上禁止运行脚本_意初的博客-CSDN博客yarn:无法加载文件 C:UsersAdministratorAppDataRoaming pmyarn.ps1,因为在此系统上禁止运行脚本。2.执行:set-ExecutionPolicy RemoteSigned 选择Y后进行回车。3.查看执行策略:get-ExecutionPolicy 查看是否为RemoteSigned。1.开始菜单中搜索PowerShell以管理员身份打开。4.关闭窗口报错解决。https://blog.csdn.net/weixin_43928112/article/details/132488190?spm=1001.2014.3001.5502


http://www.niftyadmin.cn/n/5004944.html

相关文章

JS 删除数组中的第一项和最后一项

JS 删除数组中的第一项和最后一项 需求分析 需求 JS 删除数组中的第一项和最后一项 分析 删除数组第一个元素 array.shift() /* 1. shift() 方法用于把数组的第一个元素从其中删除。 2. 返回值&#xff1a; 被删除的元素&#xff08;即数组原来的第一个元素的值&#xff09;。…

Java多线程篇(1)——深入分析synchronized

文章目录 synchronized原理概述锁升级 初始状态偏向锁偏向锁获取/重入偏向锁的撤销/重偏向和升级批量重偏向和批量偏向撤销偏向锁的释放 轻量级锁轻量级锁获取/重入轻量级锁膨胀轻量级锁释放 重量级锁重量级锁获取/重入重量级锁释放重量级锁的降级 其他锁粗化、锁消除调用hashc…

Numerical Calculation 数值计算

Numerical Calculation 数值计算 数值计算第一次实验(C语言版) C语言编程常用数值计算的高性能实现 /* 高位全0&#xff0c;低N位全1 */ #define Low_N_Bits_One(N) ((1<<N) -1)/* 高位全1&#xff0c;低N位全0 */ #define Low_N_Bits_Zero(N) (~((1<<N)…

微信小程序post请求数据传送不出去

method 是 get 方式的时候&#xff0c;header为 {"Content-Type": application/json}&#xff0c; method 为 post 时&#xff0c;header为 {"Content-Type": "application/x-www-form-urlencoded"} wx:request wx.request({url: http://..…

windows系统执行ps1(powershell)脚本文件无法识别命令的问题

常规解决办法 大家有时在powershell窗口执行命令行的时候会提示无法识别该命令 原因是在部分系统上面脚本的执行权限是禁止的 我们可以输入 get-executionpolicy 来查看当前执行策略 Restricted: 脚本不能运行(默认设置)RemoteSigned: 在本地创建的脚本可以运行&#xff0c…

java 身份证号码验证

需要编号文件 编号文件部分内容如下 11:北京市 1101:市辖区 110101:东城区 110102:西城区 110105:朝阳区 110106:丰台区 110107:石景山区 110108:海淀区 ...... 编号文件内容比较多 csdn点击 下载地址 java代码如下 import java.io.*; import java.text.ParseException; im…

vscode 调试debug rust代码的时候,中文乱码的解决办法

上次也是同样的问题&#xff0c;解决了。今天又遇到&#xff0c;我还以为是项目代码用了什么高深的地方&#xff0c;其实用chcp 65001&#xff0c;都可以解决。 一种解决方法是&#xff1a; 但建议不要用这种方法&#xff0c;因为会引起其他软件不能用&#xff08;或者出问题…

Spring Boot复用yaml文件

如果Spring Boot项目的配置过多&#xff0c;可以把一些配置项放在单独的yaml文件中&#xff0c;并以application-xxx.yaml命名。这些配置文件可以保存在当前项目的resources目录中&#xff0c;也可以保存在maven依赖的resources目录中&#xff0c;并在当前项目引入。 在applic…