当前位置:网站首页>微信小程序获取扫描二维码后携带的参数
微信小程序获取扫描二维码后携带的参数
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进行操作
}
}
边栏推荐
- 如何卸载cuda
- 记一次beego通过go get命令后找不到bee.exe的坑
- 数据库系统概论必背知识
- Resolution of cross reference in IDA
- [I.MX6UL] U-Boot移植(六) 网络驱动修改 LAN8720A
- GO同步等待组
- 3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?
- Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
- 把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(2)——将数据库转换为集群模式
- vie的刷新机制
猜你喜欢

华为、阿里等大厂程序员真的好找对象吗?

Intranet learning notes (7)

left join on和 join on的区别

高速缓存Cache详解(西电考研向)

Unity archive system - file in JSON format

Is it out of reach to enter Ali as a tester? Here may be the answer you want

AI clothing generation helps you complete the last step of clothing design

3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?

记一次beego通过go get命令后找不到bee.exe的坑

Intranet learning notes (5)
随机推荐
F - spices (linear basis)
云原生数据库VS传统数据库
Sumati gamefi ecological overview, element design in the magical world
E - average and median
PyTorch学习笔记(七)------------------ Vision Transformer
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
Advanced mathematics | proficient in mean value theorem problem solving routines summary
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
一线城市软件测试工资——你拖后腿了吗
Mall project pc--- product details page
算力服务网络:一场多元融合的系统革命
When they are in private, they have a sense of propriety
PSQL column to row
【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
Internship: use of SVN
vie的刷新机制
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(2)——将数据库转换为集群模式
当他们在私域里,掌握了分寸感
电脑端微信用户图片DAT格式解码为图片(TK版)
Of the seven levels of software testers, it is said that only 1% can achieve level 7