如何使用React + Typescript嵌入YouTube iframe?

问题描述 投票:4回答:1

打字稿似乎在这里对我不利。这是我想要嵌入的内容:

<iframe 
    width="560" 
    height="315" 
    src="https://www.youtube.com/embed/BLAH?showinfo=0" 
    frameBorder="0" 
    allow="autoplay; encrypted-media" 
    allowFullScreen></iframe>

问题是allow属性:

TS2339: Property 'allow' does not exist on type 'DetailedHTMLProps<IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>'.

...这是真的,它不在index.d.ts中。我如何强行添加此属性,或以某种方式将iframe强制转换为任何类型等?

reactjs typescript youtube
1个回答
0
投票

答案是将属性从allow更改为data-allow

© www.soinside.com 2019 - 2024. All rights reserved.