suerprisePlus
2024-08-05 30e393df7b1d89c4172a7f4bec6e80e2dc00c373
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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')