当前位置:网站首页>微信小程序获取扫描二维码后携带的参数
微信小程序获取扫描二维码后携带的参数
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进行操作
}
}
边栏推荐
- Charles 抓包工具
- 商城项目 pc----商品详情页
- The Oracle 11g RAC cluster database cannot be started due to directory permission errors
- Jetson nano from introduction to practice (cases: opencv configuration, face detection, QR code detection)
- 华为、阿里等大厂程序员真的好找对象吗?
- Kaggle 专利匹配比赛赛后总结
- Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
- GO同步等待组
- Advanced mathematics | proficient in mean value theorem problem solving routines summary
- Detailed explanation of cache (for the postgraduate entrance examination of XD)
猜你喜欢

Folding screen will become an important weapon for domestic mobile phones to share the apple market

Once beego failed to find bee after passing the go get command Exe's pit

ProcessOn制作ER过程(自定义)

转行软件测试2年了,给还在犹豫的女生一点建议

Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?

Refresh mechanism of vie

电脑端微信用户图片DAT格式解码为图片(TK版)

折叠屏将成国产手机分食苹果市场的重要武器

jwt

LeetCode 210:课程表 II (拓扑排序)
随机推荐
Dirvish Chinese document of vim
Using qdomdocument to manipulate XML files in QT
PSQL column to row
ERROR日志格式与注意点
运行时修改Universal Render Data
Advanced mathematics | proficient in mean value theorem problem solving routines summary
File system - basic knowledge of disk and detailed introduction to FAT32 file system
QT package the EXE file to solve the problem that "the program input point \u zdapvj cannot be located in the dynamic link library qt5cored.dll"
Unity archive system - file in JSON format
Talking about the advantages of flying book in development work | community essay solicitation
Folding screen will become an important weapon for domestic mobile phones to share the apple market
E - Average and Median(二分)
软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
JS regular matching numbers, upper and lower case letters, underscores, midlines and dots [easy to understand]
Jetson nano from introduction to practice (cases: opencv configuration, face detection, QR code detection)
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (2) -- convert database to cluster mode
How to uninstall CUDA
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(4)—— 修改 oracle11g rac 集群的 scanIP
如何卸载cuda