小程序中如何取到普通链接二维码中的业务参数
发布于 5 年前 作者 yduan 12801 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)

微信后台二维码规则是这么配的:https://www.xxx.com/a

实际生成的二维码链接是这样的:

https://www.xxx.com/a?id=123

  • 希望提供的能力

业务参数id是动态的,希望在小程序中获取二维码传入的id值。

目前尝试在小程序入口页面这么写无效,取不到该值:

onLoad({ id }) {
    console.log(id)
}

问题已解决:

onLoad({ q }) {
    console.log(decodeURIComponent(q))
}

只能这样,通过q参数拿到完整的二维码链接,再自行切割获取id参数。

onLoad({ id })、onLoad({ options })均无法获取到值。

5 回复

var scan_url = decodeURIComponent(options.q);

function fuck(name) {

var reg = new RegExp("[^\?&]?" + encodeURI(name) + “=[^&]+”);

var arr = scan_url.match(reg);

if (arr != null) {

return decodeURI(arr[0].substring(arr[0].search("=") + 1));

}

return “”;

}

fuck(“id”)

是小程序码吧?二维码参数获取

onLoad({ options }) {
    console.log(options.scene)
}

decodeURIComponent(options.q)

扫码 后  onLoad时候 执行 decodeURIComponent(options.q)    根据自己规则截取就好了

后台怎么配置的二维码规则 就要根据规则生成二维码

能扫码,也能打开小程序,就是获取不到参数

能扫码吗

回到顶部