Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信或者支付宝扫码拉起小程序后的参数如何获取 #1226

Closed
xiao0502 opened this issue Nov 23, 2018 · 7 comments
Closed

微信或者支付宝扫码拉起小程序后的参数如何获取 #1226

xiao0502 opened this issue Nov 23, 2018 · 7 comments

Comments

@xiao0502
Copy link

xiao0502 commented Nov 23, 2018

问题描述
微信或者支付宝扫普通链接二维码打开小程序的参数如何获取? 在mpvue或者小程序中,是通过onLoad生命周期获取,taro的componentWillMount 类似于onLoad,但是无法获取,即为undefined

复现步骤
[复现问题的步骤]

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

[或者可以直接贴源代码,能贴文字就不要截图]

onLoad(options) {
            // 普通二维码扫码进入流程
            if(options.q) {
                // ....
            }
        },

期望行为

componentWillMount(options) {
            // 普通二维码扫码进入流程
            if(options.q) {
                // ....
            }
        },

报错信息

系统信息

  • 操作系统: [e.g. Windows 10]
  • Taro 版本 [e.g. v.1.1.1]
  • Node.js 版本 [e.g. v9.0.0]
  • 报错平台 [h5, weapp]

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@taro-bot
Copy link

taro-bot bot commented Nov 23, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 24, 2018

this.$router.params

@xiao0502
Copy link
Author

this.$router.params

这个获取不了,支付宝小程序官方文档是这样的。

onlaunch(options){
    my.alert({
      title: 'app onLaunch',
      content:  JSON.stringify(options),
      success: (res) => {
          //成功处理代码段
      },
    });
  
  //获取关联普通二维码的码值,放到全局变量qrCode中
  if (options.query && options.query.qrCode) {
      this.qrCode = options.query.qrCode;
    }  
}

taro的componentWillMount生命周期是不是相当于支付宝小程序的onlaunch,但是按照支付宝小程序的文档上面也无法获取

@xiao0502
Copy link
Author

@luckyadam

@jimmy2012
Copy link

@xiao0502 问题解决了吗?我也遇到同样的问题 @luckyadam this.$router.params这个好像无效

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 1, 2019

#3313

@ZhaoTim
Copy link

ZhaoTim commented Aug 25, 2020

this.$router.params对象上有一个q属性吗?还是说this.$router上有一个q属性啊?
@Chen-jj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants