上家邀請下家,會在生成的二維碼中攜帶上家id,當下家掃碼進入小程序指定頁面,接收上家id發送給后端
在 h5 和 wxapp 中
- 生成qrcode的組件 https://ext.dcloud.net.cn/plugin?id=39
- wx小程序掃二位碼文檔
生成鏈接時
computed: {
...mapState(['userinfo']),
val() {
let val = '';
// h5直接跳網址
// #ifdef H5
val = `https://www.xxx.net/pages/register/register?code=${this.userinfo.code}`;
// #endif
// 微信小程序按按照小程序規則跳轉
// #ifdef MP-WEIXIN
// 測試的時候,填寫測試鏈接,測試好了改為動態數據
val = `https://www.xxx.net?code=123`;
// #endif
return val;
}
}
接收code時
onLoad(options) {
// #ifdef H5
if (options && 'code' in options) {
this.icode = options.code.trim();
}
// #endif
// #ifdef MP-WEIXIN
if (options && 'q' in options) {
const q = decodeURIComponent(options.q);
const querys = q
.split('?')[1]
.split('&')
.reduce((acc, it) => {
let r = it.split(/=/);
return Object.assign(acc, {
[r[0]]: r[1]
})
}, {});
if ('code' in querys) {
this.icode = querys.code.trim();
}
}
// #endif
}