【发布时间】:2018-10-11 17:09:58
【问题描述】:
所以我在 vanilla React 中遇到了问题。
我在ready() 函数中有这行代码:
var current = this;
React.createElement(
"iframe",
{id: "iframeController",
ref: "iframe",
src: "data:text/html;charset=utf-8," + escape(notification.description),
onLoad: current.iframeLoaded(this)}
)
notification.description 来自我对 this.state.notifications 中的对象所做的映射
还有这个函数跟随它
iframeLoaded(iframe) {
if(iframe) {
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}
}
但是,如果我 console.log iframeLoaded 中的 (iframe) 元素,它将返回为 null。如果我 getElementById 也是一样,但它是未定义的。
我做了一个 setTimeout 来查看它是否是组件更新问题,结果是。因此,即使在 Chrome 中,onLoad 也会在 src 有时间渲染之前触发。
我正在尝试获取高度,以便可以在窗口中设置它,允许它调整大小并获取我正在获取的 iframe 的完整高度。
任何人都可以就如何解决这个问题给我任何提示吗?
【问题讨论】:
标签: javascript reactjs iframe