uniapp 掃二維碼跳轉
阿新 • • 發佈:2020-07-26
在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 }