Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use navigator Jump to transfer values in WeChat Mini Programs

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

本篇内容介绍了"微信小程序中如何使用navigator跳转传值"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

extra-data 如何构建

由于上网查资料得知 extra-data 是 json 格式。那么就不能在 HTML 属性中直接写。

那么剩下只有在 JS 里构建了。

首先在 HTML 里,绑定 extra-data的值到 extra 变量

然后在 JS 里构建这个变量

Page({ data: { extra: { "color": '', // 动态获取 "partnerUsername": '99', }, },})

这里有个问题,就是如果 extra 里的 color 等变量是动态从远程 api 获取到的,那么应该怎么赋值。

我凭直觉写 extra.color = 'xx' ,尝试了下不行。查阅资料发现,应该这么写:

wx.request({ url: url, data: { color: '', }, header: { 'content-type': 'application/json' }, success: function (res) { that.setData({ "extra.color": app.globalData.color, }); }});

还可以在 path 属性值后面跟参数来向目标小程序传值

通过搜索发现[这篇文章](https://cloud.tencent.com/developer/article/1157552),我试了他给出的解决方案,是可行的,现在记录在下面:

// 源小程序this.setData({ colorSet: app.globalData.color, partner: app.globalData.partnerUsername,});// 目标小程序onShow: function (options) { console.log(options.query.color + options.query.partner);}

奇怪的问题(可能是bug):打开调试时,目标小程序能获取到动态的 extra-data,关闭后无法获取到

原因是我没配合法域名,所以动态从 api 获取的数据获取不到。

"微信小程序中如何使用navigator跳转传值"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report