简体   繁体   English

StencilJs 在新窗口中渲染组件

[英]StencilJs render component in new window

I am looking for ways how to render chat widget created with stenciljs in a new window using window.open.我正在寻找如何使用 window.open 在新窗口中呈现使用 stenciljs 创建的聊天小部件的方法。

The new window is opened when clicking on the widget icon and it should preserve whatever state it currently has while navigating on the website.单击小部件图标时会打开新窗口,它应该保留在网站上导航时当前的任何状态。 It should also have the styles and functionality of the parent.它还应该具有父级的样式和功能。

I understand that with React I could utilise the portal so achieve that.我知道使用 React 我可以利用门户来实现这一目标。 But does anyone know how to do that with stenciljs?但是有人知道如何用 stenciljs 做到这一点吗? Or should I try to use React with Stenciljs and see where it goes?或者我应该尝试将 React 与 Stenciljs 一起使用并查看它的去向?

Mock code:模拟代码:

<Host class="chat">
 {this.state.open ? (
   <div class="chat-wrapper">
     <chat-header customparam={this.customparam} />
     <chat-content anotherparam={this.anotherparam} />
   </div> 
  ) : (
   <open-chat
     label={this.state.openChatLabel}
     onClick={this.openChat.bind(this)} />
   )}
</Host>

So I want to open this part in new window:所以我想在新窗口中打开这部分:

<div class="chat-wrapper">
  <chat-header customparam={this.customparam} />
  <chat-content customparam={this.customparam} />
</div> 

I've already tried writing to the new window and appending header and content there.我已经尝试写入新窗口并在那里附加标题和内容。 But there is likely a better way to do it.但可能有更好的方法来做到这一点。 If any of you know how or have ideas, please share.如果你们中有人知道如何或有想法,请分享。 Will do a wrap-up once this is solved.解决后会做总结。

Edit: problem solved.编辑:问题解决。 The entire component was already included in the new window and had to assign it a different pathname, add a method for checking the window.location.href and then updating component state.整个组件已经包含在新窗口中,必须为其分配一个不同的路径名,添加一个检查 window.location.href 的方法,然后更新组件状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM