vue 生成二维码

1、安装插件

npm install qrcodejs2 --save

92003b43770a29d372e84f30b9341e0e1cd.jpg

2、使用

模板部分

...
<div class="weixin_left"><img src="../../assets/image/WePayLogo.png" class="weixinlogo" ></div>
        <div class="weixin_right">
          <div id="qrcode_id" >
          </div>
          <div>
          <img src="../../assets/image/weipaynote.png"  class="weixinnote" >
          </div>
          <div class="weixintime"><span>{{last_time}}分钟后刷新</span></div>          
        </div>
...

js部分

import QRCode  from "qrcodejs2"

...
  components: {    
    'qrcode':QRCode
  },
...
  data() {
    return {
      code_url:''
    }
  },
...
  methods: {
    ...
    qrcode:function () {        
        var that=this;
        let code_img = new QRCode(document.getElementById("qrcode_id"), {
            width: 200,
            height: 200,        // 高度
            text:  that.code_url,   // 二维码内容
            // render: 'canvas' ,   // 设置渲染方式(有两种方式 table和canvas,默认是canvas)
            background: '#f0f',   // 背景色
            // foreground: '#ff0'    // 前景色
        })
    },
    load_codeimg:function(){
      console.log(this.code_url);
      this.$nextTick(function(){
        var dom=document.getElementById("qrcode_id");
        while (dom.firstChild) {
          dom.removeChild(dom.firstChild);
        }
        this.qrcode();
        this.refreshTime();
      });
    },
    refreshTime:function(){
        //设置当前时间  倒计时30:00
        // var date = new Date();  
        // var now = date.getTime();  
        var minute=30;
        var second='00';        
        //设置截止时间  
        var str="00:00";
               
        //递归每秒调用countTime方法,显示动态时间效果  \
        var that=this;
        var temp_second=0;
        var timer=setInterval(function(){
          var now=minute+':'+second;
          that.last_time=now;
          if(second=='00'){
            minute=minute-1;
            temp_second=59;
          }

          if(temp_second==0){
            second='00';
          }
          else if(String(temp_second).length==1){
            second='0'+temp_second;
          }
          else{
            second=String(temp_second);
          }
          
          temp_second=temp_second-1;
          if(that.last_time==str){
            clearInterval(timer);
            that.load_codeimg();
          }
        },1000); 
    }
    
  }

3、结果

6dbc8f81cf0ec8de7606b0c7a6959000122.jpg

 

转载于:https://my.oschina.net/qingqingdego/blog/3035234

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值