赞
踩
小程序码缩小后太细, 不好扫, 还是改成二维码扫
记录解析该二维码
onLoad(e) { if (e.shareTimeline) { // 以单页面启动-朋友圈分享出的单页面 this.shareTimeline = e.shareTimeline; let param = { certId: e.certId, uid: e.uid, unionid: e.unionid, openid: e.openid, } this.initData(param) } else if (e.scene) { // 以小程序码扫码方式启动, - 目前图片都是放的二维码,可能不走 const scene = decodeURIComponent(e.scene) let sceneArr = scene.split("=") let param = { certId: sceneArr[1] } this.initData(param) } else if (e?.q) { // 以小程序码转换为二维码的方式启动, 解析q对象 const q = decodeURIComponent(e.q) // 获取到二维码原始链接内容 // const scancode_time = parseInt(e.scancode_time) // 获取用户扫码时间 UNIX 时间戳 let cert_id = this.$cjs.getUrlSingleParam('cert_id', q) //调用工具函数获取url中传递的参数 let param = { certId: cert_id } this.initData(param) } else { // 以小程序/APP的应用内跳转 进入的,直接取路由参数 let param = e; this.initData(param) } },
直接看第三个else
e.q 就是扫码后, 必须接受的参数, 也是判断依据
export let getUrlSingleParam = function (key, url = location.search) {
const reg = new RegExp("(\\?|&)" + key + "=([^&]*)(&|$)");
const r = url.match(reg);
if (r != null) {
return r[2];
// return unescape(r[2]);//unescape函数显示已经废弃
}
return null;
}
具体看这个:enter>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。