vue3-yuanma/packages/vue/src/index.ts

39 lines
733 B
TypeScript
Raw Normal View History

2018-09-20 03:19:25 +00:00
import {
h,
render,
Component,
ComponentOptions,
createComponentInstance
} from '@vue/renderer-dom'
2018-09-20 01:52:24 +00:00
2018-09-20 03:19:25 +00:00
class Vue extends Component {
static h = h
static render = render
2018-09-20 01:52:24 +00:00
2018-09-20 03:19:25 +00:00
constructor(options: ComponentOptions & { el: any }) {
super()
if (!options) {
return
2018-09-20 01:52:24 +00:00
}
2018-09-20 03:19:25 +00:00
const vnode = h(options)
const instance = createComponentInstance(vnode, options._normalized, null)
vnode.children = instance
function mount(el: any) {
const dom = document.querySelector(el)
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
}
}
}
export default Vue