-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
91 lines (90 loc) · 2.82 KB
/
index.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;
(function () {
let vRometeJs = {}
vRometeJs.install = function (Vue) {
Vue.component('remote-css', {
props: {
hrefs: {
type: Array,
required: true
}
},
data() {
return {
linkNodes: []
}
},
render(createElement) {
return createElement('div')
},
created() {
this.head = document.head || document.getElementsByTagName('head')[0]
this.hrefs.forEach(href => {
let link = document.createElement('link')
link.href = href
link.rel = 'stylesheet'
this.linkNodes.push(link)
this.head.appendChild(link)
})
},
destroyed() {
this.linkNodes.forEach(element => {
this.head.removeChild(element)
});
}
})
Vue.component('remote-js', {
data() {
return {
scriptNodes: []
}
},
props: {
srcArr: {
type: Array,
required: true
}
},
render(createElement) {
return createElement('div')
},
created() {
this.head = document.head || document.getElementsByTagName('head')[0]
this.index = 0
this.createScript(this.srcArr[this.index])
},
destroyed() {
this.scriptNodes.forEach(element => {
this.head.removeChild(element)
});
},
methods: {
createScript(src) {
let script = document.createElement('script')
script.src = src
script.type = 'text/javascript'
this.scriptNodes.push(script)
this.head.appendChild(script)
script.onload = () => {
if (this.index < this.srcArr.length - 1) {
this.index += 1
this.createScript(this.srcArr[this.index])
} else {
this.$emit('scriptLoad')
}
}
}
}
})
}
if (typeof exports === 'object') {
module.exports = vRometeJs
} else if (typeof define === 'function' && define.amd) {
define([], function () {
return vRometeJs
})
} else if (window.Vue) {
window.vRometeJs = vRometeJs
Vue.use(vRometeJs)
}
})()