Vue 源码阅读(六)组件化

All Vue components are also Vue instances, and so accept the same options object (except for a few root-specific options) and provide the same lifecycle hooks.

定义子类

/src/core/global-api/extend.js

通过 Vue.extend 构建了一个 Vue 的子类。

create-component

/src/core/vdom/create-component.js

render 阶段会调用 create-component ,实际上就是调用 Vue.extend 来实例化一个 Vue 类。

然后

侧面可以印证,作者确实也是把 Vue 看做一个组件来实现的

export function initMixin (Vue: Class<Component>) {}

整个组件系统在不断实例化 Vue 类。

题外话

Vue 有一个强劲的内核

  • Vuex 其实通过实例化一个 Vue 的实例来实现响应式
  • event bus 可以通过实例化 Vue 来实现
    原文作者:siwuxie
    原文地址: https://segmentfault.com/a/1190000013598013
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞