React应用程序之间可以通信吗? [英] Is it possible to communicate between React Applications?

查看:81
本文介绍了React应用程序之间可以通信吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是三个React应用程序的旅程,我想使用一些数据,这些数据从应用程序1到应用程序2,从应用程序2到应用程序3.

My project is a journey of three react applications, I want to use some data from application 1 to application 2 and application 2 to application 3.

如果要传递的数据很小,我将其传递给第二个应用程序的url中的查询参数.

If data to be passed is small, i passed it in query parameter in url of 2nd application.

如果数据很大或不公开,我计划将其作为帖子发送,将由应用程序2接收.

And if data is large or private, i am planning to send it as a post which will be received by application 2.

React应用程序之间是否有更好的通信方式? 我可以将每个范围应用程序制作为可以将其数据公开给应用程序2的库吗?

Is there any better way of communicating between react applications? Can i make each reach application as a Library which can expose its data to application 2?

推荐答案

您可以使用postMessage(

You could use the postMessage (MDN link), which is now supported in every browser.

这是一个跨域,基于事件的消息传递系统,具有熟悉的API,直接在浏览器中运行.

It's a cross-domain, event-based messaging system running directly in the browser, with a familiar API.

在目标页面上对消息进行处理之前,请务必先检查消息的来源!

Be sure to check the message's source before acting on them in your destination page!

这篇关于React应用程序之间可以通信吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆