function Skip(type = true) {
|
this.async = type;
|
}
|
|
/**
|
* 获取XMLHttpRequest对象(提供客户端同http服务器通讯的协议)
|
*
|
*/
|
Skip.prototype.getXmlHttpRequest = function () {
|
if (window.XMLHttpRequest) // 除了IE外的其它浏览器
|
return new XMLHttpRequest();
|
else if (window.ActiveXObject) // IE
|
return new ActiveXObject("MsXml2.XmlHttp");
|
};
|
Skip.prototype.includeJsText = function (rootObject, jsText) {
|
if (rootObject != null) {
|
var oScript = document.createElement("script");
|
oScript.type = "text/javascript";
|
oScript.text = jsText;
|
rootObject.appendChild(oScript);
|
}
|
};
|
Skip.prototype.includeJsSrc = function (rootObject, fileUrl) {
|
if (rootObject != null) {
|
var oScript = document.createElement("script");
|
oScript.type = "text/javascript";
|
oScript.src = fileUrl;
|
rootObject.appendChild(oScript);
|
}
|
};
|
/**
|
* 加载js
|
*
|
* @param {String} url js路径
|
*/
|
Skip.prototype.addJs = function (url) {
|
var oXmlHttp = this.getXmlHttpRequest();
|
var Skipthis = this;
|
oXmlHttp.onreadystatechange = function () {
|
if (oXmlHttp.readyState === 4) { //当执行完成以后(返回了响应)所要执行的
|
if (oXmlHttp.status === 200 || oXmlHttp.status === 304) { //200有读取对应的url文件,404表示不存在这个文件
|
Skipthis.includeJsSrc(document.body || document.head, url);
|
} else {
|
console.log('XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')');
|
}
|
}
|
};
|
oXmlHttp.open('GET', url, Skipthis.async); //url为js文件时,ie会自动生成 '<script src="*.js" type="text/javascript"> </scr ipt>',ff不会
|
oXmlHttp.send(null);
|
if (oXmlHttp.status === 404) {
|
console.log(url + ' is not found');
|
} else {
|
Skipthis.includeJsText(document.body || document.head, oXmlHttp.responseText);
|
}
|
};
|
let _Skip = new Skip(false);
|
|
let currentScript = document.currentScript && document.currentScript.src;
|
let endIndex = currentScript.indexOf('vue-elementui.js');
|
let rootUrl = currentScript.substring(0, endIndex);
|
|
let link = document.createElement("link");
|
link.rel = "stylesheet";
|
link.type = "text/css";
|
link.href = rootUrl + 'element-ui/theme-chalk/index.css';
|
document.head.appendChild(link);
|
_Skip.addJs(rootUrl+ 'vue/vue.js')
|
_Skip.addJs(rootUrl+ 'element-ui/index.js')
|