当前位置:网站首页>微信小程序获取扫描二维码后携带的参数
微信小程序获取扫描二维码后携带的参数
2022-06-24 23:41:00 【YZHD】
微信小程序获取扫描二维码后携带的参数
1、decodeURIComponent解析生成二维码的链接。
/** * 生命周期函数--监听页面加载 */
onLoad: function(options) {
if (options.scene) {
//获取二维码的携带的链接信息
let qrUrl = decodeURIComponent(options.scene)
console.log(qrUrl)
this.setData({
//获取链接中的参数信息
actId: utils.getQueryString(qrUrl, 'actId'),
shareUserId: utils.getQueryString(qrUrl, 'shareUserId'),
})
}
},
2、utils中获取链接中所携带的参数
// 解析链接中的参数
let getQueryString = function (url, name) {
console.log("url = " + url)
console.log("name = " + name)
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
console.log("r = " + r)
console.log("r[2] = " + r[2])
return r[2]
}
return null;
}
//导出方法,外部调用
module.exports = {
getQueryString: getQueryString,
}
避坑:
onLoad (option) {
console.log(option)
}
这时可以接收到 拿着参数去请求数据等等操作~
假如你的小程序要发布了
这时候应该改变获取参数的方式,因为正式发布后的获取的参数和在开发者工具中是不一样的,这个坑!!!。下面代码是你获取正式发布小程序后的入口二维码中参数的代码,scene是微信生成二维码方法的一个参数,用来写你要在二维码中携带的参数
onLoad (option) {
console.log(option)
if (option.scene) {
let obj = decodeURIComponent(option.scene)
... // 这里就是你拿着参数obj进行操作
}
}
边栏推荐
- How to uninstall CUDA
- I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating
- Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
- 背了八股文,六月赢麻了……
- LINQ query (3)
- Sumati gamefi ecological overview, element design in the magical world
- Refresh mechanism of vie
- F - spices (linear basis)
- random list随机生成不重复数
- [live review] battle code pioneer phase 7: how third-party application developers contribute to open source
猜你喜欢
14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
AI clothing generation helps you complete the last step of clothing design
Lihongyi, machine learning 6 Convolutional neural network
Sumati gamefi ecological overview, element design in the magical world
会自动化—10K,能做自动化—20K,你搞懂自动化测试没有?
背了八股文,六月赢麻了……
It's 2022, and you still don't know what performance testing is?
Advanced mathematics | proficient in mean value theorem problem solving routines summary
入坑机器学习:一,绪论
保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
随机推荐
centos7.3修改mysql默认密码_详解Centos7 修改mysql指定用户的密码
NPM package publishing tutorial
Transformers Roberta如何添加tokens
PE file infrastructure sorting
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source
ACL access control of squid proxy server
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
Processon producer process (customized)
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
会自动化—10K,能做自动化—20K,你搞懂自动化测试没有?
Random list random generation of non repeating numbers
算力服务网络:一场多元融合的系统革命
PE文件基础结构梳理
Leetcode 210: curriculum II (topological sorting)
Planification du réseau | [quatre couches de réseau] points de connaissance et exemples
软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?
3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?
Unity archive system - file in JSON format
Software testing salary in first tier cities - are you dragging your feet