Skip to main content

节点

案例

声明

/**
* 显示弹框
*/
KmcDialog.showInstance = function(properties) {
if (!document.getElementById("KmcDialog")) {
let props = properties || {};
let div = document.createElement('div');
div.setAttribute('id', 'KmcDialog');
document.body.appendChild(div);
ReactDOM.render(React.createElement(KmcDialog, props), div);
}
}
/**
* 删除弹框
*/
KmcDialog.removeInstance = function() {
if(document.getElementById("KmcDialog")) {
document.getElementById('KmcDialog').remove();
}
}

调用

在需要使用的地方直接调用:

KmcDialog.showInstance({
isShow: true
});
KmcDialog.removeInstance();

参考

React-动态插入节点组件 React组件插入DOM流程(源码分析) react项目中对dom元素样式修改的另一种方法以及将组件插入到node节点中 React将组件渲染到指定DOM节点