加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 弹出窗口中的React与父窗口通信的任何方式?

发布时间:2020-12-15 20:43:43 所属栏目:百科 来源:网络整理
导读:我有一个OAuth进程弹出一个窗口,但是当我登录时,重定向到OAuth回调页面发生在弹出窗口而不是父窗口(window.opener).这可能有点hacky,但我想让弹出窗口告诉父母“我们被授权
我有一个OAuth进程弹出一个窗口,但是当我登录时,重定向到OAuth回调页面发生在弹出窗口而不是父窗口(window.opener).这可能有点hacky,但我想让弹出窗口告诉父母“我们被授权!”.

这实际上有效:

OAuthCallback = React.createClass({
  displayName: 'OAuthCallback',render() {
    window.opener.console.log('hello parent window');

    return (
      <div>
        Hi,OAuth is process is done.
      </div>
    )
  }
});

但是我想知道是否有某些方法可以让弹出窗口告诉父窗口调用prop函数,例如this.props.oauthSucceeded().

当您无法在组件之间建立任何父子关系或兄弟关系时,React建议您设置一个事件系统.

For communication between two components that don’t have a
parent-child relationship,you can set up your own global event
system. Subscribe to events in componentDidMount(),unsubscribe in
componentWillUnmount(),and call setState() when you receive an event.
Flux pattern is one of the possible ways to arrange this.

见https://facebook.github.io/react/tips/communicate-between-components.html

浏览window.postMessage进行跨窗口通信(https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读