微信小程序二维码制作

微信小程序二维码制作

帮助

二维码: weapp-qrcode-canvas-2d

img

HTML

<canvas type="2d" style="width: 200px; height: 200px;" id="myQrcode"></canvas>

引入文件

import drawQrcode from '../../utils/weapp.qrcode.esm'

JS

const query = wx.createSelectorQuery()
        query.select('#myQrcode')
          .fields({
            node: true,
            size: true
          })
          .exec((res) => {
            var canvas = res[0].node
            // 调用方法drawQrcode生成二维码
            drawQrcode({
              canvas: canvas,
              canvasId: 'myQrcode',
              width: 200,
              padding: 20,
              background: '#ffffff',
              foreground: status == '过期' ? 'orange' : '#87d068',
              text: qrCode,
            })
            // 获取临时路径(得到之后,想干嘛就干嘛了)
            wx.canvasToTempFilePath({
              canvasId: 'myQrcode',
              canvas: canvas,
              x: 0,
              y: 0,
              width: 200,
              height: 200,
              destWidth: 200,
              destHeight: 200,
              success(res) {
                console.log('二维码临时路径:', res.tempFilePath)
              },
              fail(res) {
                console.error(res)
              }
            })
          })
posted @ 2021-02-02 17:17  孤常一人  阅读(560)  评论(0编辑  收藏  举报