Infogram 嵌入代码未在 React 中呈现

Infogram embed code not rendering in React

我有以下来自 infogram 的嵌入代码,它没有在我的 React 应用程序中呈现。

code looks as below:
<div class="infogram-embed" data-id="861ca70e-552c-4a4f-960a-4c7e7ff62881" data-type="interactive" data-title="Step by Step Charts"></div><script>!function(e,t,s,i){var n="InfogramEmbeds",o=e.getElementsByTagName("script")[0],d=/^http:/.test(e.location)?"http:":"https:";if(/^\/{2}/.test(i)&&(i=d+i),window[n]&&window[n].initialized)window[n].process&&window[n].process();else if(!e.getElementById(s)){var r=e.createElement("script");r.async=1,r.id=s,r.src=i,o.parentNode.insertBefore(r,o)}}(document,0,"infogram-async","https://e.infogram.com/js/dist/embed-loader-min.js");</script><div style="padding:8px 0;font-family:Arial!important;font-size:13px!important;line-height:15px!important;text-align:center;border-top:1px solid #dadada;margin:0 30px"><a href="https://infogram.com/861ca70e-552c-4a4f-960a-4c7e7ff62881" style="color:#989898!important;text-decoration:none!important;" target="_blank">Step by Step Charts</a><br><a href="https://infogram.com" style="color:#989898!important;text-decoration:none!important;" target="_blank" rel="nofollow">Infogram</a></div>

我正在使用 html React 解析库,它在所有其他情况下都工作得很好。

知道为什么这不起作用吗?

谢谢

不确定这是否有帮助,以下是我如何让它与 React 一起工作 https://jsfiddle.net/wonderwhy_er/4dt28xzL/6/

或代码 在HTML

<script>!function(e,t,s,i){var n='InfogramEmbeds',o=e.getElementsByTagName('script')[0],d=/^http:/.test(e.location)?'http:':'https:';if(/^\/{2}/.test(i)&&(i=d+i),window[n]&&window[n].initialized)window[n].process&&window[n].process();else if(!e.getElementById(s)){var r=e.createElement('script');r.async=1,r.id=s,r.src=i,o.parentNode.insertBefore(r,o)}}(document,0,"infogram-async","https://e.infogram.com/js/dist/embed-loader-min.js");</script>


<div id="app"></div>

在 JS 中

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

  render() {
    return (
      <div>
        <div class="infogram-embed" data-id="861ca70e-552c-4a4f-960a-4c7e7ff62881" data-type="interactive" data-title="Step by Step Charts">
        </div>
      </div>
    )
  }
}

ReactDOM.render(<App />, document.querySelector("#app"))

我把脚本部分移走了,它只是从 Infogram 请求一个加载器,你不需要在 React 渲染器中执行它,所以我只是把它移到了页面的 header 之类的地方。

你在嵌入的末尾还有其他东西,我删除了它并且可以工作。检查 link.