qlongbg

1.在小程序中引入weapp-qrcode.js到utils文件夹下:

2.在需要转化二维码的页面引入

const QRCode = require(\'../../utils/weapp-qrcode.js\')
3.canvas的宽高需要自适应,那么需要进行尺寸转换
const W = wx.getSystemInfoSync().windowWidth;
const rate = 750.0 / W;

// 300rpx 在6s上为 150px
const qrcodeWidth = 300 / rate;

4.生成二维码

 getqrcode(item) {

    qrcode = new QRCode(`${item.couponUserId}`, {
      usingIn: this,
      image: \'../../images/connection.png\',
      width: qrcodeWidth,
      height: qrcodeWidth,
      colorLight: "white",
      correctLevel: QRCode.CorrectLevel.L
    });
    let _urls = config.previewHost
    qrcode.makeCode(`${_urls}/coupon-use?id=${item.couponUserId}`);
    
  },

其中`${item.couponUserId}`是wxml中canvas的id

text是需要转换为二维码的字符串

usingIn为可选参数,组件间中要使用,传this

image为默认生成二维码的图片

width和height分别是绘制出的二维码长宽,这里设置为跟canvas同样的长宽

colorDark和colorLight为二维码交替的两种颜色

correctLevel是二维码的纠错级别,默认为高级

若果你需要再次生成二维码可调用qrcode.makeCode(\'需要转换的地址\')
 

分类:

技术点:

相关文章:

  • 2021-12-13
  • 2021-07-28
  • 2022-12-23
  • 2021-12-27
  • 2021-09-15
猜你喜欢
  • 2021-12-01
  • 2021-09-15
  • 2022-12-23
  • 2021-12-09
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案