获取微信小程序码中的参数

获取小程序码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 获取小程序码参数

// 获取某个url参数的方法
getQueryString (name, params) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
// var reg = new RegExp('(' + name + '=)', 'i')
var r = params.match(reg)
if (r != null) {
return decodeURIComponent(r[2])
}
return null
},
onLoad (options) {
let that = this
// 获取活动id
if (options.scene) {
// 由于生成的小程序码会把参数都放在scene里面,并且做了urlEncode,所以先要url decode一下
var scene = decodeURIComponent(options.scene)
var id = this.getQueryString('id', scene)
if (id) {
that.actid = id
}
} else {
if (options.id) {
that.actid = options.id
}
}
}