feat: support defining data in constructor/initialzers

This commit is contained in:
Evan You
2018-10-11 13:54:35 -04:00
parent d9e3ad72c0
commit 60e803ce62
6 changed files with 116 additions and 101 deletions

View File

@@ -2,33 +2,21 @@ import {
h,
render,
nextTick,
Component,
createComponentInstance,
createComponentClassFromOptions
} from '@vue/renderer-dom'
// Note: typing for this is intentionally loose, as it will be using 2.x types.
class Vue extends Component {
class Vue {
static h = h
static render = render
static nextTick = nextTick
// Note: typing for this is intentionally loose, as it will be using 2.x types.
constructor(options: any) {
super()
if (!options) {
return
}
// in compat mode, h() can take an options object and will convert it
// to a 3.x class-based component.
const Component = createComponentClassFromOptions(options)
// convert it to a class
const Component = createComponentClassFromOptions(options || {})
const vnode = h(Component)
// the component class is cached on the options object as ._normalized
const instance = createComponentInstance(vnode, Component, null)
// set the instance on the vnode before mounting.
// the mount function will skip creating a new instance if it finds an
// existing one.
vnode.children = instance
function mount(el: any) {
const dom = typeof el === 'string' ? document.querySelector(el) : el