6 Star 27 Fork 7

dyb881/react to typescript

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dom.ts 996 Bytes
一键复制 编辑 原始数据 按行查看 历史
dyb881 提交于 2019-01-29 12:45 +08:00 . 代码优化,以及antd二次封装
/**
* 插入标签到页面
* @param {HTMLElement} element 待插入元素
* @param {HTMLElement} body = document.body 插入的容器
* @return {Promise} 标签插入后返回
*/
export const installElement = (element: HTMLElement, body = document.body) =>
new Promise(resolve => {
body.appendChild(element);
if (element instanceof HTMLLinkElement || element instanceof HTMLScriptElement) {
element.onload = () => resolve(element);
} else {
resolve(element);
}
});
/**
* 插入脚本
* @param {string} src 脚本地址
*/
export const installScript = (src: string) => {
const script = document.createElement('script');
script.src = src;
return installElement(script);
};
/**
* 插入样式
* @param {string} href 样式地址
*/
export const installLink = (href: string) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
return installElement(link);
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/dyb881/react-ts.git
git@gitee.com:dyb881/react-ts.git
dyb881
react-ts
react to typescript
master

搜索帮助