mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
30 lines
801 B
JavaScript
30 lines
801 B
JavaScript
/**
|
|
* 异步加载js文件
|
|
* @author tengge / https://github.com/tengge1
|
|
* @param {*} url js文件url
|
|
* @param {*} callback 回调函数
|
|
*/
|
|
function loadJs(url, callback) {
|
|
var head = document.getElementsByTagName('head')[0];
|
|
var script = document.createElement('script');
|
|
script.type = 'text/javascript';
|
|
script.src = url;
|
|
head.appendChild(script);
|
|
if (typeof (callback) === 'function') {
|
|
script.onload = script.onreadystatechange = function () {
|
|
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
|
|
callback();
|
|
script.onload = script.onreadystatechange = null;
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
/**
|
|
* js工具类
|
|
*/
|
|
const JsUtils = {
|
|
load: loadJs
|
|
};
|
|
|
|
export default JsUtils; |