【发布时间】:2018-05-17 12:52:45
【问题描述】:
该问题的典型解决方案在 React 中不起作用,因为它动态生成的组件结构和事件模型,而不是传统的静态 HTML。我尝试了 react-iframe-resizer-super 但没有找到完美的解决方案。
我的代码:
import React, {PropTypes} from 'react';
import ReactIframeResizer from 'react-iframe-resizer-super';
class Frame extends React.Component {
constructor() {
super();
}
componentDidUpdate() {
const iframeResizerOptions = {
// log: true,
// autoResize: true,
checkOrigin: false,
// resizeFrom: 'parent',
// heightCalculationMethod: 'max',
// initCallback: () => { console.log('ready!'); },
// resizedCallback: () => { console.log('resized!'); },
};
}
render() {
return (
<div style={{position: 'relative'}}>
<IframeResizer iframeResizerOptions={iframeResizerOptions}>
<iframe scrolling="no" src="https://en.wikipedia.org/wiki/Main_Page" allowfullscreen
style={{width:'100%', height:'100%'}}
}}></iframe>
</IframeResizer>
</div>
);
}
}
然后我得到以下错误:
Uncaught ReferenceError: IframeResizer is not defined
React 中有没有办法将 iframe 的高度设置为其可滚动内容的高度,或者有没有其他方法可以归档这个要求?
我参考以下链接:
【问题讨论】: