-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathmount.js
50 lines (35 loc) · 1.05 KB
/
mount.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
import Vue from 'vue'
import VueWrapper from './VueWrapper'
import addSlots from './lib/addSlots'
import addGlobals from './lib/addGlobals'
import addProvide from './lib/addProvide'
Vue.config.productionTip = false
function createElem () {
const elem = document.createElement('div')
document.body.appendChild(elem)
return elem
}
export default function mount (component, options = {}) {
let elem
const attachToDocument = options.attachToDocument
if (attachToDocument) {
elem = createElem()
delete options.attachToDocument // eslint-disable-line no-param-reassign
}
if (options.intercept) {
const globals = addGlobals(options.intercept)
Vue.use(globals)
}
// Remove cached constructor
delete component._Ctor // eslint-disable-line no-param-reassign
if (options.provide) {
addProvide(component, options)
}
const Constructor = Vue.extend(component)
const vm = new Constructor(options)
if (options.slots) {
addSlots(vm, options.slots)
}
vm.$mount(elem)
return new VueWrapper(vm, attachToDocument)
}