We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关键点,使用 extends 继承 Xiao , 在构造方法 constructor 里面调用 super(definition) 。
extends
Xiao
constructor
super(definition)
class Xiao{ /** * 全局注册组件 */ static component(id: string, definition?: Object) { if (globalComponent[id]) { return globalComponent[id] } if (!definition) { return null } const newClass = class extends Xiao { constructor() { super(definition) } } for (let key in definition) { newClass[key] = definition[key] } globalComponent[id] = newClass log('globalComponent', globalComponent) return newClass } }
在 insert 钩子里面,调用 子组件的 $mount 函数,渲染dom。
insert
$mount
function setComponentHook(vnode: any, vm: Xiao) { if (!vnode.sel) { return } // 查看是否组成了组件? const Comp = Xiao.component(vnode.sel) if (Comp) { log('组件', Comp) vnode.data.hook = { insert: (vnode) => { log('component vnode', vnode) let app =new Comp() app._parent = vm app.$mount(vnode.elm) } } } if (vnode.children) { vnode.children.forEach(function (e) { setComponentHook(e, vm) }, this) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
实现组件注册功能
关键点,使用
extends
继承Xiao
, 在构造方法constructor
里面调用super(definition)
。给虚拟节点增加 insert hook
在
insert
钩子里面,调用 子组件的$mount
函数,渲染dom。The text was updated successfully, but these errors were encountered: