【问题标题】:Iframes and React.js - How to embed a youtube video into my appiframe 和 React.js - 如何将 youtube 视频嵌入到我的应用中
【发布时间】:2017-11-26 16:51:25
【问题描述】:

我正在尝试了解如何将 youtube 嵌入到我的应用中。

import React from "react"
import Pageheader from 'react-bootstrap/lib/Pageheader';
import ResponsiveEmbed from 'react-bootstrap/lib/ResponsiveEmbed';
import Grid from 'react-bootstrap/lib/Grid';

export default class Services extends React.Component {
  render() {
    return (
        <div id = "services">
            <Pageheader justified>
                About us
                <small>M2 Consulting is Bringing Small Businesses to the Agile century</small>
                <ResponsiveEmbed a16by9>
                    <embed src="https://youtu.be/uC9VtVnuPD0"/>
                </ResponsiveEmbed>
            </Pageheader>
        </div>
    )
  }
}

这是我目前拥有的。

我尝试了几种不同的方法来正确显示,但发现使用 youtube 中的嵌入代码等方法会产生多个错误。我正在尝试复制这个网站以及它如何显示嵌入视频。

https://moodmap.app/

【问题讨论】:

    标签: javascript reactjs iframe youtube


    【解决方案1】:

    您可以使用iframe 元素来实现此目的。无需依赖另一个 npm 包。

    <iframe src='https://www.youtube.com/embed/E7wJTI-1dvQ'
            frameborder='0'
            allow='autoplay; encrypted-media'
            allowfullscreen
            title='video'
    />
    

    顺便说一句,如果你想知道为什么embed URL 看起来像它,你可以去任意一个Youtube video,点击Share,然后你会立即看到我们只需要附加@987654327 @Youtube'sURL.

    【讨论】:

    • 因此,当您按“分享”时,YouTube 给您的 HTML 之间的唯一区别是 allowFullScreenframeBorder 的大写。修复它,你就完成了。
    • 你好,youtuber。
    • 我需要的一个改变:export const YoutubeEmbed = (embedId) =&gt; embedId &amp;&amp; ( &lt;iframe ... /&gt;);
    • jk 没有解决我的问题。出于某种原因,它仅在我对 embedId 进行硬编码时才有效。它正在尝试获取embed/[Object object]
    • 为了完整起见,事实证明这是我生成embedId的代码的问题。我希望你可以编辑 cmets,这样我就不必发三遍了,但是唉。
    【解决方案2】:

    你可以使用react组件react-youtube

    【讨论】:

    猜你喜欢
    • 2011-11-23
    • 2016-01-15
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2017-11-05
    • 1970-01-01
    • 2012-05-29
    相关资源
    最近更新 更多