onLoad(options) {
if (options.scene) {
console.log("has scene");
var scene = decodeURIComponent(options.scene);
console.log("scene is ", scene);
var arrPara = scene.split("&");
var arr = [];
for (var i in arrPara) {
arr = arrPara[i].split("=");
wx.setStorageSync(arr[0],arr[1]);
console.log("setStorageSync:",arr[0],"=",arr[1]);
}
} else {
console.log("no scene");
}
},
记录一下坑!!!!!!!!!!!
在开发阶段
onLoad (option) {
console.log(option)
}
这时可以接收到 拿着参数去请求数据等等操作~
假如你的小程序要发布
了
这时候应该改变获取参数的方式,因为正式发布后的获取的参数和在开发者工具中是不一样的,这个坑!!!。下面代码是你获取正式发布小程序后的入口二维码中参数的代码,scene是微信生成二维码方法的一个参数,用来写你要在二维码中携带的参数
onLoad (option) {
console.log(option)
if (option.scene) {
let obj = decodeURIComponent(option.scene)
... // 这里就是你拿着参数obj进行操作
}
}