javascript - 如何在 React 组件中嵌入 text/html?

标签 javascript html reactjs

我正在尝试将 text/html 嵌入到 React Modal 组件中。但是当我用 electron 运行我的应用程序时,Google Inspector 会显示一些错误。

Uncaught invariant.js:38 Uncaught Invariant Violation: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX. This DOM node was rendered by Example.

解决方案:替换 <object>通过 <webview>

这是我的代码

import React from 'react';
import SkyLight from 'react-skylight';

class Example extends React.Component {
  constructor(props){
    super(props);
  }

  render() {
    return (
      <div>
        <section>
          <h1>React SkyLight</h1>
          <button onClick={() => this.refs.simpleDialog.show()}>Ouvrez le modal</button>
        </section>
        <SkyLight  hideOnOverlayClicked ref="simpleDialog" title="Hi, I'm a simple modal">
          <object type="text/html" data="http://www.example.com" style="width:100%; height:100%">
            <p>backup content</p>
          </object>
        </SkyLight>
      </div>
    )
  }
}

Example.displayName = 'Example';

export default Example;

最佳答案

试着改变这条线

<object type="text/html" data="http://www.example.com" style="width:100%; height:100%">

有了这个

    <object type="text/html" data="http://www.example.com" 
style={{width:'100%', height:'100%'}}>

样式属性需要一个 json 对象,有关更多详细信息,您可以查看此链接 https://facebook.github.io/react/docs/dom-elements.html#style

关于javascript - 如何在 React 组件中嵌入 text/html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934534/

相关文章:

reactjs - 使用 TypeScript 和 NPM 链接创建 React 应用程序 : Enums causing Module parse failed

javascript - 在 React 中将新商品添加到我的购物车

javascript - 将 unicode 数字数组读取为 unicode 字符串(在 javascript 中)

javascript - 如何显示嵌套在div中的网页?

javascript - Chart.js Line,负点的不同填充颜色

javascript - 模糊不透明的 div 背景(页面背景似乎通过 div 模糊)

html - 如何为 HTML5 readAsText 使用文件名字符串而不是输入按钮

javascript - 如何使用 JavaScript 验证 YouTube 视频 ID

javascript - 如何将 jQuery UI 选择菜单与按钮对齐?

javascript - 在 create-react-app 中有条件地导入 Assets