微信小程序前端生成小程序码

1.js get后面携带参数值不能用引号包裹

var appid = 'wx27affeb9e3336157'
var secret = '69e0dac741e19432fc0a3ab662281800'
wx.request({
    url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
    method: 'GET',
    success: function(res) {
        console.log('res.access_token',res.data.access_token)
        wx.request({
          url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + res.data.access_token,
          method: 'POST',
          data: {
            scene: 1012,
            // 是否为Png,默认jpeg
            is_hyaline: true,
            // 是否自动取色
            auto_color:true,
            page: 'pages/mine/mine',
          },
          responseType: 'arraybuffer',
          complete: function(res) {   
            that.setData({
              code: wx.arrayBufferToBase64(res.data)
          })        
        },
    })
  }
})

2.wxml 显示小程序码

<image src="data:image/png;base64,{{code}}" mode="widthFix"></image>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。