首页 > 微信 > 详细

微信小程序-二维码组件

时间:2020-11-03 20:47:26      阅读:56      评论:0      收藏:0      [点我收藏+]

 

<canvas 
  class=‘canvas‘ 
  canvas-id=‘canvas‘ 
  style="width:{{qrcodeWidth}}px; height:{{qrcodeWidth}}px;margin:{{marginTB}}rpx auto;"
></canvas>

 

{
  "component": true
}

 

const QRCode = require(‘../../utils/weapp-qrcode.js‘)
import rpx2px from ‘../../utils/rpx2px.js‘
let qrcode;
let defaultWidth = 300; //二维码默认宽度

Component({
    properties: {
        //二维码码数
        code: {
            type: String,
            value: ‘‘ 
        },
        //二维码默认宽度
        width: {
            type: Number,
            value: defaultWidth 
        },
        //二维码默认margin上下边距
        marginTB: {
            type: Number,
            value: 0
        }
    },
    data: {
        qrcodeWidth: rpx2px(defaultWidth), 
    },
    ready: function() {
        this.setData({qrcodeWidth: rpx2px(this.properties.width)})
        qrcode = new QRCode(‘canvas‘, {
            usingIn: this, // usingIn 如果放到组件里使用需要加这个参数
            text: this.properties.code,
            image: ‘‘,
            width: rpx2px(this.properties.width),
            height: rpx2px(this.properties.width),
            colorDark: "#010101",
            colorLight: "white",
            correctLevel: QRCode.CorrectLevel.H,
        });
    },
    methods: {}
})

 

源码地址:https://github.com/tomfriwel/weapp-qrcode

 

微信小程序-二维码组件

原文:https://www.cnblogs.com/XUYIYUAN/p/13922039.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!