小程序 服务器端调用接口获取小程序太阳码 前端接收问题

 

 

 

 

 

获取 scene 值

scene 字段的值会作为 query 参数传递给小程序/小游戏。用户扫描该码进入小程序/小游戏后,开发者可以获取到二维码中的 scene 值,再做处理逻辑。

调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 encodeURIComponent

小程序(记得解码)

Page({
  onLoad (options) {
    // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    const scene = decodeURIComponent(options.scene)
   //split() 方法用于把一个字符串分割成字符串数组。如果一个参数是scene='id=1'多个用&连接scene='id=1&good=1322'  最大32字符,不会太多参数
  一个参数时候 id=scene.split('=')[1]
  多个参数时候 id=(scene.split('&')[0]).split('=')[1]   this.setData({     id: id   } })

  



 

posted @ 2020-09-11 10:42  瑶玲  阅读(707)  评论(0编辑  收藏  举报