zoukankan      html  css  js  c++  java
  • vue项目中使用生成动态二维码

    vue项目中使用QRCode.js生成二维码

    看了好多blog,也尝试了多种方法,最后在QRCode.js文档上终于看懂了一些,一路踩着坑,终于做出了符合自己心意的东西。

    1、环境准备

    (1)、首先在项目中安装qrcodejs2:

    npm i qrcodejs2

    (2)、在组件中调用,我是在哪儿使用哪儿调用的。(ps:在main.js中引入会报错)

    2、代码
    
    <template>  
        <div class="qrBox">    
            <h3>手机扫描,安全登录</h3>    
            <div id="qrCode" ref="qrCodeDiv"></div>    
            <p>      
                <span @click="reg">免费注册</span>    
            </p>  
        </div>
    </template>
    
    <script>  
        // 引入qrcode  
        import QRCode from 'qrcodejs2';   
        export default {        
            name: "loginCode",      
            props:['codeName'], //是获取当前时间毫秒数,通过“父传子”方式传递下来
            data(){         
                return{            
                    text:''          
                }      
            },     
            methods:{        
                bindQRCode() {          
                    this.text = this.codeName;      
                    // new QRCode(this.$refs.qrCodeDiv, this.text)          
                    new QRCode(this.$refs.qrCodeDiv, {            
                        text: this.text.toFixed(0), //text必须是字符串
                         180,            
                        height: 180,            
                        colorDark: "#333333", //二维码颜色            
                        colorLight: "#ffffff", //二维码背景色            
                        correctLevel: QRCode.CorrectLevel.L//容错率,L/M/H          
                    })       
                },        
                reg(){         
                    this.$router.push("/adminLoginTwo")        
                    }      
                },     
            mounted () {        
                this.$nextTick(function () {          
                    this.bindQRCode();        
                })      
            }    
        }
    </script>
    
    <style scoped lang="stylus">  
        .qrBox   
             100%    
            height: 100%    
            text-align center   
            h3      
                line-height 40px     
                margin-bottom 20px    
            #qrCode      
                 180px      
                height: 180px     
                margin 0 auto      
                padding 10px      
                border 1px solid #ddd    
            p      
                line-height 30px      
                text-align right      
                margin-top 30px      
                padding-right 100px      
            span        
                cursor pointer
    </style>
    
    3、效果展示

    在这里插入图片描述

  • 相关阅读:
    剑指offer-树的子结构
    剑指offer-二叉搜索树的后序遍历序列
    剑指offer-调整数组顺序使奇数位于偶数前面
    剑指offer-包含min函数的栈
    剑指offer-从上往下打印二叉树
    剑指offer-链表中倒数第k个结点
    剑指offer-合并两个排列的链接
    剑指offer-替换空格
    剑指offer-旋转数组的最小数字
    剑指offer-数字在排序数组中出现的次数
  • 原文地址:https://www.cnblogs.com/xm0328/p/13901817.html
Copyright © 2011-2022 走看看