先说如何使用
Helper.modal('组件', 'z-index层级');
然后看一下代码
// modal 弹出一个独立的框
modal(Component, zIndex) {
let body = document.body;
let showDom = document.createElement("div");
// 设置基本属性
showDom.style.position = 'absolute';
showDom.style.top = '0px';
showDom.style.left = '0px';
showDom.style.width = Browser.width;
showDom.style.height = Browser.height;
showDom.style.zIndex = zIndex || Browser.FLOAT_VIEW_INDEX;
body.appendChild(showDom);
// 自我删除的方法
let close = () => {
ReactDom.unmountComponentAtNode(showDom);
body.removeChild(showDom);
}
ReactDom.render(
<Component onClose={close} />,
showDom
);