微信小程序 - 扫描小程序码进入小程序并获取参数,实现绑定上下级(分销功能)

在进入的页面加上onLoad方法,获取参数

onLoad(options) {
  if(options.scene) {
    let scene = decodeURIComponent(options.scene);
    console.log(scene)
    // 后续处理scene
  }
}

或者,在app.js的onLaunch方法中获取

onLaunch(options) {
  if(options.query.scene) {
    let scene = decodeURIComponent(options.query.scene);
    console.log(scene)
    // 后续处理scene
  }
}

在开发阶段可以使用微信开发者工具进行场景模拟测试,编译后相当于扫描小程序码进入该页面

另外,解释一下decodeURIComponent():

定义和用法

decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

语法

decodeURIComponent(URIstring)

 参数

参数 描述
URIstring 必需。一个字符串,含有编码 URI 组件或其他要解码的文本。

猜你喜欢

转载自blog.csdn.net/mossbaoo/article/details/84143453
今日推荐