码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • vue2踩坑之项目:生成二维码使用vue-print-nb打印二维码


    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 } //自定义指令中注册 

    1. //html
    2. "clickPrint(form)">打印
    3. <el-drawer
    4. title="图片打印"
    5. :visible.sync="drawer"
    6. :direction="direction"
    7. :before-close="handleClose"
    8. size="80%">
    9. <div style="position: absolute;right: 110px;top: 15px;padding-left: 30px;">
    10. <el-button type="primary" v-print="print">打印el-button>
    11. div>
    12. <div id="printView">
    13. <div class="img-content-first"
    14. :class=" index >= 5?'img-content':'img-content-first'"
    15. v-for="(item,index) in erwmList"
    16. :key="index">
    17. <img :src=item.imgBase class="img" />
    18. <div class="text">{{ item.connectorCode }}div>
    19. div>
    20. div>
    21. el-drawer>
    22. //script
    23. // 单组件引用打印插件
    24. import print from 'vue-print-nb'
    25. import {getxxxx} from "../../api/xxxx/xxxx.js" // 二维码接口
    26. //data
    27. // 抽屉 批量打印
    28. data() {
    29. return {
    30. //表单筛选条件
    31. form:{
    32. status:'',
    33. name:'',
    34. //....
    35. },
    36. drawer: false,
    37. direction: 'rtl',
    38. erwmList:[], //二维码列表
    39. erweimaImg: '',
    40. // 打印插件
    41. print: {
    42. id: "printView", //打印的区域的id名
    43. popTitle: "管理平台", // 打印配置页上方标题
    44. extraHead: "", //最上方的头部文字,附加在head标签上的额外标签,使用逗号分隔
    45. extraCss: "",
    46. },
    47. }
    48. }
    49. //js
    50. // 批量打印 点击事件
    51. clickPrint (item) {
    52. // console.log(item,'ss');
    53. if (
    54. (item.status=== "" || null || undefined) &&
    55. (item.name === ""||null||undefined)
    56. )
    57. {
    58. this.drawer = false
    59. this.$alert('', '请选择筛选条件!', {
    60. confirmButtonText: '确定',
    61. });
    62. } else {
    63. getxxxx(item).then(res => {
    64. //console.log(res);
    65. this.erwmList= res
    66. if (res) {
    67. this.drawer = true
    68. }
    69. })
    70. }
    71. },
    72. // 批量打印 抽屉关闭事件
    73. handleClose (done) {
    74. this.drawer = false
    75. // this.$confirm('确认关闭?')
    76. // .then(_ => {
    77. // done();
    78. // })
    79. // .catch(_ => {});
    80. },
    81. //css
    82. <style scoped lang="less">
    83. ......
    84. .img-content-first{
    85. display: inline-block;
    86. border: 2px solid #000;
    87. margin: 0 0 0 30px;
    88. .text{
    89. margin: 0 auto;
    90. text-align: center;
    91. color: #000;
    92. font-size: 18px;
    93. margin-top: -24px;
    94. }
    95. }
    96. .img-content{
    97. display: inline-block;
    98. border: 2px solid #000;
    99. margin: 50px 0 0 30px;
    100. .text{
    101. margin: 0 auto;
    102. text-align: center;
    103. color: #000;
    104. font-size: 18px;
    105. margin-top: -24px;
    106. }
    107. }
    108. // @media print {
    109. // #print .img-content {
    110. // width: 150px;
    111. // height: 150px;
    112. // }
    113. // }
    114. style>
    115. <style media="print" lang="less">
    116. @page {
    117. size: auto;
    118. }
    119. @media print {
    120. // html {
    121. // zoom: 70%; //设置打印页面的缩放,大小
    122. // margin: 0 auto;
    123. // }
    124. #printView .img-content-first{
    125. border: 2px solid #000;
    126. // width: 190px;
    127. height: 185px;
    128. margin: 10px 0 0 15px;
    129. }
    130. #printView .img-content{
    131. border: 2px solid #000;
    132. // width: 190px;
    133. height: 185px;
    134. margin: 30px 0 0 15px;
    135. }
    136. #printView .img{
    137. // width: 190px;
    138. height: 180px;
    139. }
    140. #printView .text{
    141. margin: 0 auto;
    142. text-align: center;
    143. color: #000;
    144. font-size: 18px;
    145. margin-top: -24px;
    146. }
    147. }

    上一篇文章,

    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

  • 相关阅读:
    Numpy那些事
    【图论】Floyd
    设计师找灵感,这5个网站就够了
    业内人士真心话:只会测试没有前途的,我慌了......
    光伏电池建模及温度光照的影响曲线MATLAB仿真
    分布式程序中YARN中的角色
    计算机毕业设计(附源码)python云讲座系统
    Jenkins: 配置自动化发布脚本
    React整理总结(二、组件化开发)
    Python ML实战-工业蒸汽量预测02-数据探索
  • 原文地址:https://blog.csdn.net/weixin_43928112/article/details/132725143
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号