首页 > 其他分享 >vue 项目 生成二维码

vue 项目 生成二维码

时间:2022-10-10 16:11:44浏览次数:42  
标签:vue top qrcodejs2 生成 QRCode 二维码 technician height

Vue项目生成二维码  

一:引入qrcodejs2

终端运行  2选1
npm i qrcodejs2 

npm i qrcodejs2-fix 

引入 qrcodejs2 ,生成二维码时 出现如下错误:

 

 

 解决办法:所以当前项目需要引入 qrcodejs2-fix 

二、生成代码(一)

<template>
  <body>
  <div class="qr_main" >
    <div id="qrCode" ref="qrCodeDiv"></div>
  </div>
  </body>
</template>
<script>
    import QRCode from "qrcodejs2-fix"
    export default {
        data() {
            return {
                technician: {},
            }
        },
        onShow() {
            this.technician = getApp().technician();
        },
        mounted:function() {
            this.$nextTick(function () {
                this.bindQRCode();
            })
        },
        methods: {
            bindQRCode() {
                new QRCode(this.$refs.qrCodeDiv, {
                    text: this.technician.technician_no, // 需要转换为二维码的内容
                    width: 200,
                    height: 200,
                    colorDark: "#333333", //二维码颜色
                    colorLight: "#ffffff", //二维码背景色
                    correctLevel: QRCode.CorrectLevel.Q//容错率,L/M/H
                })
            }
        },
    }
</script>
<style >
    .qr_main {
      width:300px;
      height:300px;
      margin: 0 auto; /*水平居中*/
      position: relative;
    }
 
    #qrCode {
      display: inline-block;
      margin: 0 auto; /*水平居中*/
      position: relative;
      top: 15%;
     }

</style>

三、生成代码(二) uni-app 弹窗

<view class="content">
 <view class="other">
    <uni-col :span="6" @click="showTechnicianQrCode()">
    <uni-icons type="auth-filled" color="#c31d33" size="25"></uni-icons>
    <view>显示二维码</view>
    </uni-col>
  </view>
<view :hidden="showQRCode" class="qr_content"> <view >   <div id="qrCode" ref="qrCodeDiv"></div> <view @click="hideTechnicianQrCode()" class="qr_buttons"> <text class="qr_button">确定</text> </view> </view> </view>
</view>
<script>
import QRCode from "qrcodejs2-fix" export default { data() { return { technician: { // id:62 }, showQRCode:true ,//默认隐藏 qrcode:{}, } }, onl oad() {...}, onShow() { this.technician = getApp().technician(); }, methods: { showTechnicianQrCode() { if (this.technician.id) { let dom = document.getElementById("qrCode"); while (dom.firstChild) { dom.removeChild(dom.firstChild); //因为重复生成二维码,所有需要移除之前的dom } this.bindQRCode(); this.showQRCode=false; // uni.navigateTo({ // url: "/pages/my/technicianqrcode" // }) } else { this.login(); } }, hideTechnicianQrCode(){ this.showQRCode=true; }, bindQRCode() { this.qrcode= new QRCode(this.$refs.qrCodeDiv, { text: this.technician.technician_no, // 需要转换为二维码的内容 width: 150, height: 150, colorDark: "#333333", //二维码颜色 colorLight: "#aaffff", //二维码背景色 correctLevel: QRCode.CorrectLevel.Q//容错率,L/M/H/Q }) } } } </script> <style> #qrCode { display: inline-block; position: relative; left: 25%; top: 15%; width: 100%; height: 100%; } .qr_content { position: fixed; top: 50%; left: 50%; width: 280rpx; height: 240rpx; margin-left: -270rpx; margin-top: -270rpx; border: 10px solid white; background-color: white; z-index: 1002; overflow: auto; } .qr_buttons{ text-align: center; font-size: 30rpx; margin-top: 30rpx; background-color: #aaffff; }</style>

 

标签:vue,top,qrcodejs2,生成,QRCode,二维码,technician,height
From: https://www.cnblogs.com/QiangQiangDai/p/16776044.html

相关文章

  • vue pdf预览
    用到的插件是vuepdf1、对于不能通过npminstall安装的,需要去官网下载打包好的文件,文件夹大概是这个样子的,  然后在用到的.vue文件中引入就ok了  创建一个展示pd......
  • Vue3 Vite3 状态管理 pinia 基本使用、持久化、在路由守卫中的使用
    在《基于vite创建vue3项目》一文中整合了pinia,有不少伙伴不知道pinia是什么,本文简单介绍pinia。主要包括三方面:pinia的基本用法,在《基于vite创建vue3项目》......
  • 随机生成字符串,支持字母、数字、下划线
    //随机生成64位字符,支持字母、数字、下划线//this.clientSecretValue输入框的值randomRange(){letrandomStr=''letcharStr='ABCDEF......
  • VUEe 插件收集
    VsCode插件清单代码提示  Vue2SnippetsVetur插件让vue文件代码高亮VueVSCodeSnippets自动生成vue模板内容插件LiveServer实时刷新网页BracketPairColorizer彩......
  • vuepress 搭建组件库文档
    项目地址项目地址:https://github.com/YolandaKisses/YolandaKisses.github.io演示地址:https://yolandakisses.github.io/目录结构├─docs│└─.vuepress│ ......
  • vue中如何使用定义好的变量设置css样式
    前言在做项目的时候,通常会遇到需要在HTML标签上绑定变量来设置样式,对于这种需求,共有两种情况。实现第一种情况如果是对于代码中实实在在存在的HTML标签,我们可以直......
  • 高性能(无需判重)批量生成优惠券码生成方案
    usingSystem.Text;namespacexxxxxx{publicclassCouponCodeUtilV2{privatestaticreadonlychar[]_codePool={'z','N','x','5','h','......
  • 富文本插件quill生成内容后,字体样式未生效
    后台返回的富文本显示的时候字体大小无变化或不居中使用uniapp或者vue都可以使用一下方式解决场景描述:1、在富文本编辑器内,对文字进行了排版,以下为文字居中样式2、在页面......
  • Vue系列---【at Socket.writeAfterFIN [as write] (net.js:441:14) at PoolWorker
    1.问题描述:前端是vue项目,打包和打镜像的时候,本地没问题,jenkins物理机打流水线也没问题,但是到容器云平台使用自带的流水线打包打镜像的时候,就报错了。上次成功上线的代......
  • Vue3 Echarts 3D柱状图搭建
    最近学习大数据,需要数据可视化,所以特地去学习了一下echarts,通过springboot+vue整合了echarts三维柱状图。先看效果。  因为我是初学vue脚手架,对一些vue内置方法不是......