小编mel*_*ist的帖子

React / Typescript无法识别iframe属性

我正在尝试嵌入一个播放带有框架边框的Vimeo的iframe,并使用MyOwnComponent使其具有全屏属性,如下所示:

const MyOwnVimeoComponent = () => {
return (
    <div>
        <iframe 
            src="https://player.vimeo.com/video/VIMEOID" 
            width="640" 
            height="360" 
            frameborder="0" 
            webkitallowfullscreen 
            mozallowfullscreen 
            allowfullscreen
        ></iframe>
    </div>
);}
Run Code Online (Sandbox Code Playgroud)

但是,我得到的错误是:

[ts] Property 'frameborder' does not exist on type 'HTMLProps<HTMLIFrameElement>'
Run Code Online (Sandbox Code Playgroud)

同为webkitallowfullscreenmozallowfullscreenallowfullscreen

在研究了StackOverflow上的其他类似问题之后,它使我检查了Typescript的lib.d.ts文件并查看了<HTMLIFrameElement>接口和变量声明。

实际上,接口确实具有属性frameborderallowfullscreen类型,但是仍然会引发错误。我会理解它是否仅对和引发了错误webkitallowfullscreenmozallowfullscreen但我通常对这里发生的事情感到困惑。

如果有人能指出我正确的方向,将不胜感激。

供参考,这似乎是lib.d.ts文件的相关部分:

interface HTMLIFrameElement extends HTMLElement, GetSVGDocument {
align: string;
allowFullscreen: boolean;
allowPaymentRequest: boolean;
border: string;
readonly contentDocument: Document;
readonly contentWindow: Window;
frameBorder: string;
frameSpacing: any;
height: string;
hspace: …
Run Code Online (Sandbox Code Playgroud)

iframe declaration typescript reactjs

4
推荐指数
2
解决办法
2972
查看次数

标签 统计

declaration ×1

iframe ×1

reactjs ×1

typescript ×1