【问题标题】:How to use <webview> methods inside a react component如何在反应组件中使用 <webview> 方法
【发布时间】:2017-12-07 18:28:14
【问题描述】:

我正在构建一个仪表板,该仪表板使用 ReactJS 和电子链接到各种服务器。现在在一个页面中我有一个按钮,当它被点击时,它会使用标签在应用程序中呈现一个“webview”,但我没有得到整个页面,因为它需要一些额外的标题,比如语言。我在https://electron.atom.io/docs/api/webview-tag/ 的官方文档中看到,对于使用 webview 方法,我们首先必须加载 webview 元素,但我尝试了我想到的所有可能性,但无法提出解决方案。

如果有人可以告诉我应该在哪里以及如何加载 webview 元素以及如何使用组件内的 webview 方法,非常感谢。

谢谢。

【问题讨论】:

    标签: reactjs webview electron


    【解决方案1】:

    保留webview的ref,最初不加载任何url

    <WebView autosize={true} ref={(input) => { this.webview = input; }} src="data:text/plain" />
    

    在您的 componentDidUpdate() 中加载带有额外标题的 url

    if (this.webview) {
      this.webview.loadUrl(url, {
        extraHeaders: ""
      });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-21
      • 2016-01-17
      • 2021-01-31
      • 1970-01-01
      • 2022-12-17
      • 2020-06-28
      相关资源
      最近更新 更多