«

react ifame自适应高度

emer 发布于 2019-7-15 10:21   2517 次阅读     


import React from 'react';
import ReactDOM from 'react-dom';
import { Row, Col, Icon, Button, Layout, Menu, Card } from 'antd';

export default class Iframe extends React.Component {

  constructor() {
    super();
    this.state = {
        iFrameHeight: '0px'
    }
}

  render() {
    return (
      <iframe 
                  title="key"
                style={{width:'100%', height:this.state.iFrameHeight, overflow:'visible'}}
                onLoad={() => {
                    const obj = ReactDOM.findDOMNode(this);
                    this.setState({
                        "iFrameHeight":  obj.contentWindow.document.body.scrollHeight + 'px'
                    });
                }} 
                ref="iframe" 
                src="/api/dealerList/info?sysDealerId=37009" 
                width="100%" 
                height={this.state.iFrameHeight} 
                scrolling="no" 
                frameBorder="0"
            />
    );
  }
}