点击按钮扫描二维码

<button class='deaBtn' bindtap='scancode'>扫描二维码</button>scancode: function(){    // 允许从相机和相册扫码    wx.scanCode({      success(res) {        console.log(res);        wx.showToast({          title: '成功',          icon: 'success',          duration: 2000        })      },      fail: (res) =>{        console.log(res);        wx.showToast({          title: '失败',          icon: 'none',          duration: 2000        })      }    })  },

扫描成功返回的结果如下:

属性类型说明
resultstring所扫码的内容
scanTypestring所扫码的类型
charSetstring所扫码的字符集
pathstring当所扫的码为当前小程序的合法二维码时,会返回此字段,内容为二维码携带的 path
rawDatastring原始数据,base64编码

 注意:扫描失败可能是需要重新登录,也可能是网络连接

官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.scanCode.html

TAG标签: 小程序微信二维码扫描

http://www.xiaochengxub.com/read-106496.html