惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - 折翼的飞鸟

React中 state值根据props传入值变化的静态方法 getDerivedStateFromProps 微信小程序分享图片显示自定义内容 Taro4.x 引入 taro-ui 组件库 Taro4.x引入redux报错:TypeError: middleware is not a function uniapp+vue3 微信小程序使用mqtt通信 uniapp+vue3 在App.vue中如何设置全局调用方法 Taro 在页面中import包、组件、样式文件的顺序自定义规则 Taro优化VirtualList虚拟列表组件 Taro 引入moment.js打包过大 Taro 打包体积分析 React:消息订阅(subscribe)-发布(publish)机制 Taro 插件引入 Taro: chooseLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json Taro 主包vendors.js文件过大 Taro自定义Tabbar Taro 微信转支付宝小程序: 问题八 TypeError: Function(...) is not a function Taro微信转支付宝小程序:问题七 引入的文件图片文件名不能有@符号 Taro微信转支付宝小程序:问题六 同时编译微信小程序和支付宝小程序 Taro微信转支付宝小程序:问题五 编译时没有报错,工具中却莫名奇妙的错误提示
Taro 支付宝小程序Page页获取小程序启动时的参数
折翼的飞鸟 · 2022-11-23 · via 博客园 - 折翼的飞鸟

支付宝扫码直接跳转到小程序指定的页面时,支付宝将其二维码链接转成小程序的启动参数query来传递。此时在Taro中Page页面获取这些参数

支付宝如何获取各种场景的启动参数 参考文档

在页面层面(page.js中),通过 my.getLaunchOptionsSync 获取启动参数

// 这里是支付宝小程序原生的代码
Page({ onLoad:
function() { let options = my.getLaunchOptionsSync(); console.log(options) } })

/*** -------------------------------------------------------------------------------------------------------------- ***/

// 在Taro框架中,通过生命周期 componentDidMount 中获取,此时如果项目兼容支付宝、微信,要先判断是否是支付宝环境
import Taro, { getCurrentInstance } from '@tarojs/taro';

componentDidMount () {
let routerParams = getCurrentInstance().router.params; // 获取url参数,此时支付宝小程序的启动参数是无法获取
if (process.env.TARO_ENV === 'alipay') {
// 获取支付宝小程序的启动参数,格式如下:

{"path":"pages/index/index","query":{"qrCode":"https://xxxx"},"scene":"1011","apiCategory":"default"}

let {query}= my.getLaunchOptionsSync(); // 获取支付宝小程序的启动参数
routerParams = query;
}
}