微信小程序扫二维码获取二维码地址携带的参数

627 阅读1分钟

例:二维码地址:api.weixin.qq.com?num=123456

在微信小程序中获取:

onLoad: function (options) {
  if(options.q){
     let qrUrl=decodeURIComponent(options.q)
     let reg=new RegExp('(^|&|/?)invcode=([^&|/?]*)(&|/?|$)','i')
     let r=qrUrl.substr(1).match(reg)
     this.setData({num:r[2]})
  }
}

参考:www.cnblogs.com/lin127/p/12…