在 React 组件中,我有一个 iframe:
<iframe
css={styles.videoIframe}
width="853"
height="480"
src={embedlink}
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
title={title}
/>
当我检查 DOM 时,我看到 src
已更改为 data-src
?
<iframe width="853" height="480" data-src="http://www.youtube.com/embed/youtube-id-here" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" title="The title"></iframe>
我没有看到渲染的嵌入 YouTube 视频?可能是因为将属性更改为data-src
?
最佳答案
我最终为此使用了 no-cookie 嵌入。将我的嵌入变量更改为以下内容后,它工作正常:
const embedLink = `https://www.youtube-nocookie.com/embed/${youtubeId}`;
另请参阅this回答。
关于reactjs - iframe src 属性在我的 React 应用程序中更改为 data-src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66240349/