微信小程序-扫码获取信息

功能描述:点击扫码按钮,获取二维码信息;用户可以在用二维码生成工具生成一个二维码测试

.wxml页面定义一个扫码按钮:

 <text class="saoma" bindtap="addGoosInfo">扫码</text>

点击扫码,调用对应的.js文件中addGooInfo接口:

 addName: "",
/**扫码 */
  addGoosInfo: function() {
    var that = this;
    var show;
    wx.scanCode({
      success: (res) => {
        this.show = "结果:" + res.result;
        console.log(this.show)
        that.setData({
          addName: this.show
        })
        wx.showToast({
          title: '扫码成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: (res) => {
        wx.showToast({
          title: '扫码失败',
          icon: 'success',
          duration: 2000
        })
      },
      complete: (res) => {}
    })
  
  },

其中,addName的值可以在对应的.wxml页面中赋值给{{ addName }}

你可能感兴趣的:(html,reactjs)