2018-09-20 03:19:25 +00:00
|
|
|
import {
|
|
|
|
h,
|
|
|
|
render,
|
2018-09-20 03:43:27 +00:00
|
|
|
nextTick,
|
2018-10-10 01:10:30 +00:00
|
|
|
createComponentInstance,
|
|
|
|
createComponentClassFromOptions
|
2018-09-20 03:19:25 +00:00
|
|
|
} from '@vue/renderer-dom'
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-10-11 17:54:35 +00:00
|
|
|
class Vue {
|
2018-09-20 03:19:25 +00:00
|
|
|
static h = h
|
|
|
|
static render = render
|
2018-09-20 03:43:27 +00:00
|
|
|
static nextTick = nextTick
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-10-11 17:54:35 +00:00
|
|
|
// Note: typing for this is intentionally loose, as it will be using 2.x types.
|
2018-10-09 17:59:30 +00:00
|
|
|
constructor(options: any) {
|
2018-10-11 17:54:35 +00:00
|
|
|
// convert it to a class
|
|
|
|
const Component = createComponentClassFromOptions(options || {})
|
2018-10-10 01:10:30 +00:00
|
|
|
const vnode = h(Component)
|
2018-10-16 19:47:51 +00:00
|
|
|
const instance = createComponentInstance(vnode, Component)
|
2018-09-20 03:19:25 +00:00
|
|
|
|
|
|
|
function mount(el: any) {
|
2018-09-20 03:43:27 +00:00
|
|
|
const dom = typeof el === 'string' ? document.querySelector(el) : el
|
2018-09-20 03:19:25 +00:00
|
|
|
render(vnode, dom)
|
|
|
|
return instance.$proxy
|
|
|
|
}
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-09-20 03:19:25 +00:00
|
|
|
if (options.el) {
|
|
|
|
return mount(options.el)
|
|
|
|
} else {
|
|
|
|
;(instance as any).$mount = mount
|
|
|
|
return instance.$proxy
|
2018-09-20 01:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:59:30 +00:00
|
|
|
interface Vue {
|
|
|
|
$mount(el: any): any
|
2018-10-08 22:09:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 01:52:24 +00:00
|
|
|
export default Vue
|