微信小程序扫普通链接二维码打开小程序
-
微信后台 - 管理 -开发管理 -扫普通链接二维码打开小程序
![]()
![]()
-
代码实现
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (option: any) {
if (option.hasOwnProperty('q') && option.q) {
// 通过下面这步解码,可以拿到url的值
const url = decodeURIComponent(option.q) // 对url中携带的参数提取处理
let jsonUrl = this.GetwxUrlParam(url);
this.setData({
'id': jsonUrl.id, // 微信后台里配置的id
})}
},GetwxUrlParam(url: any) {
let theRequest: any = {};
if (url.indexOf("#") != -1) {
const str = url.split("#")[1];
const strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
} else if (url.indexOf("?") != -1) {
const str = url.split("?")[1];
const strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
return theRequest;
},



浙公网安备 33010602011771号