微信小程序生成二维码

主要通过 weapp.qrcode.js 在 微信小程序 中,快速生成二维码。使用(自适应版本,使用rpx为单位)

参考:https://github.com/tomfriwel/weapp-qrcode

1、先在 wxml 文件中,创建绘制的 canvas,并定义好 width, height, canvasId 。

<canvas style="width:{{qrcode_w}}px; height:{{qrcode_w}}px;" canvas-id="canvas"></canvas>

2、引入js文件,并且计算好宽高

const QRCode = require('../../utils/weapp-qrcode.js');

const W = wx.getSystemInfoSync().windowWidth;

const rate = 750.0 / W;

// 这里布局二维码的宽高是400rpx,所以以下

const qrcode_w = 400 / rate;

getQrCode(list) {  // 生成二维码

    new QRCode('canvas', {

      text: ‘二维码内容’,

      width: this.data.qrcode_w,

      height: this.data.qrcode_w,

      correctLevel: QRCode.CorrectLevel.H,//非必须,二维码纠错级别,默认值为高级,取值:{ L: 1, M: 0, Q: 3, H: 2 }

      // image: '',//非必须,在 canvas 上绘制图片,层级高于二维码,v1.0.0+版本支持,更多可参考drawImage

    })

 },

贴图

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。