uniapp 掃普通鏈接二維碼打開小程序


上家邀請下家,會在生成的二維碼中攜帶上家id,當下家掃碼進入小程序指定頁面,接收上家id發送給后端

在 h5 和 wxapp 中

生成鏈接時

  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
  }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM