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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ChibiMarukoChan/article/details/82934385

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

在.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 }}

其中,wx.scancoad和wx.showToast是微信小程序的内置函数。详细操作见:

https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html

猜你喜欢

转载自blog.csdn.net/ChibiMarukoChan/article/details/82934385