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

支付宝扫码打开小程序怎么获取数据 #11724

Closed
TheKonka opened this issue Apr 26, 2022 · 3 comments
Closed

支付宝扫码打开小程序怎么获取数据 #11724

TheKonka opened this issue Apr 26, 2022 · 3 comments
Labels
T-alipay Target - 编译到支付宝小程序 to be closed V-3 Version - 3.x

Comments

@TheKonka
Copy link
Member

这个特性解决了什么问题?

useRouter() 获取不到

这个 API 长什么样?

useRouter() 能获取到

@TheKonka
Copy link
Member Author

自问自答了,
修改app.tsx

  onLaunch(option: any) {
    if (process.env.TARO_ENV === "alipay" && option.query?.qrCode) {
     // 
    }
  }

  componentDidShow(option: any) {
    if (process.env.TARO_ENV === "alipay" && option.query?.qrCode) {
   //
    }
  }

不知是否有其他方法

@AdvancedCat AdvancedCat added V-3 Version - 3.x T-alipay Target - 编译到支付宝小程序 labels Apr 27, 2022
@AdvancedCat
Copy link
Member

@konka-king 都自问自答了,可以尝试自问自修啊 😄

@AdvancedCat
Copy link
Member

AdvancedCat commented Apr 28, 2022

Taro提供的 useRouter 主要用于获取页面链接的查询参数,比如通过 Taro.navigateTo({url:'../index/index?a=1&b=2'}), 你可以通过 useRouter 获取到页面参数 {a: '1', b: '2'}。同理,使用 Taro.getCurrentInstance().router 也是如此。

但是,通过扫描二维码启动小程序,要获取二维码中的参数,则需要从 onLaunch 生命周期中获得,通常它长这样:
alipays://platformapi/startapp?appId=1999&query=number%3D1&page=x%2Fy%2Fz
参见支付宝文档

Taro App组件支持 onLaunch 生命周期 或者 调用 getLaunchOptionsSync()

综上,useRouter 符合预期。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-alipay Target - 编译到支付宝小程序 to be closed V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants