2021-02-07 18:03:59 +08:00

45 lines
826 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ReactDOM from 'react-dom';
/**
* 渲染组件
* @param comp
* @param container
*/
export function render(comp: any, container: HTMLElement) {
ReactDOM.render(comp, container);
}
/**
* 卸载组件
* @param container
*/
export function destroy(container: HTMLElement) {
ReactDOM.unmountComponentAtNode(container);
}
/**
* 创建一个 div 节点,并放到 container默认放到 body 上
* @param title
* @param container
* @param id 容器 id
*/
export function createDiv(container: HTMLElement = document.body): HTMLElement {
const div = document.createElement('div');
container.appendChild(div);
return div;
}
/**
* 移除 dom 元素
* @param dom
*/
export function removeDom(dom: HTMLElement) {
const parent = dom.parentNode;
if (parent) {
parent.removeChild(dom);
}
}