//此组件将指定组件渲染到指定的dom节点上 import * as React from 'react' import * as ReactDom from 'react-dom'; interface MountProps { rootDom?: any, className?: string, children: any } export default class Mount extends React.Component { popup: any; rootDom: any componentDidMount() { let { rootDom = document.getElementById('bs-main') } = this.props; this.popup = document.createElement('div'); this.popup.setAttribute('class', this.props.className || '') this.rootDom = rootDom; this.rootDom.appendChild(this.popup); this._renderLayer() } componentDidUpdate() { this._renderLayer(); } componentWillUnmount() { this.rootDom.removeChild(this.popup); } _renderLayer() { ReactDom.render(this.props.children, this.popup); } render() { return null; } }