這是什麼意思呢? 我來解釋一下。
意思是:在別人通過掃面你的小程序碼,並且你的小程序碼是帶參數的,那麼在線上的版本就要加一個此方法進行轉碼;
decodeURIComponent(query.scene)
這是我在線上版本打印出來的,這是微信自動給參數轉碼了。
這裏和我們在微信開發工具是不一樣的,所以在線上就要多一個判斷了。
app.js 爲 options.query.scene
正常頁面 options.scene
if (options.scene){ //這裏爲線上操作
//此處的二維碼 page/index/index?brokerId=123
let scene = decodeURIComponent(options.scene);
console.log('index scene: ', scene) //brokerId=123 爲字符串,需要我們去分割
params.brokerId = scene.split("=")[1];
} else if (options.brokerId && options.brokerId !== 'undefined' ){//這裏爲開發環境
params.brokerId = options.brokerId;
}
if (options.scene){
//此時參數爲兩個 二維碼爲 page/index/index?A=123&B=456
let scene = decodeURIComponent(options.scene);
console.log('detail scene: ', scene)
let arr = scene.split('&');
let A = arr[0].split('=')[1];
let B = arr[1].split('=')[1];
wx.getStorage({
key: 'phoneNumber',
success(res) {
_this.getHouseDetail(A, B, res.data);
}
})
}else{
wx.getStorage({
key: 'phoneNumber',
success(res) {
_this.getHouseDetail(options.A, options.B, res.data);
}
})
}
自己調試可以添加編譯模式去模擬
注意:前面要加scene={你的參數轉碼}
放一個轉碼的網站:https://meyerweb.com/eric/tools/dencoder/