首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用react等前端技术时,在网页中显示嵌入的社交数据

在使用react等前端技术时,在网页中显示嵌入的社交数据
EN

Stack Overflow用户
提问于 2018-11-01 19:35:21
回答 1查看 34关注 0票数 0

如何在reactjs中显示来自twitter的嵌入式社交数据,该reactjs已经有了脚本标记,可以在适当的位置对twitter进行样式和渲染,并将其硬编码到数据库表中,并包含一些内容?在大型站点中,它工作得很好。在前端基于它是不工作的。

例如,以文本形式存储在db表中的内容:

代码语言:javascript
复制
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I just published “Making Sense of React Hooks” <a href=""></a></p>&mdash; Dan Abramov (@dan_abramov) <a href="https://twitter.com/dan_abramov/status/1057319198626594816?ref_src=twsrc%5Etfw">October 30, 2018</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum

当使用react时,这个脚本twitter不会加载默认的小部件布局,周围有一些段落作为硬编码内容。

EN

回答 1

Stack Overflow用户

发布于 2018-11-01 21:08:07

问题出在脚本标记中。您可以直接将其添加到index.html中,也可以像这样使用componentDidMount

代码语言:javascript
复制
componentDidMount () {
     const script = document.createElement("script");

     script.src = "https://platform.twitter.com/widgets.js";
     script.async = true;

     document.body.appendChild(script);
}

选中此Jsfiddle,或者您可能想要选中此npm package

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53100490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档