/src/core/index.js
/src/core/instance/index.js
function Vue (options) { if (process.env.NODE_ENV !== 'production' && !(this instanceof Vue) ) { warn('Vue is a constructor and should be called with the `new` keyword') } this._init(options) }/** Vue.prototype._init*/initMixin(Vue) /** Object.defineProperty(Vue.prototype, '$data', dataDef)* Object.defineProperty(Vue.prototype, '$props', propsDef)* Vue.prototype.$set = set* Vue.prototype.$delete = del* Vue.prototype.$watch*/stateMixin(Vue) /** Vue.prototype.$on* Vue.prototype.$once* Vue.prototype.$off* Vue.prototype.$emit*/eventsMixin(Vue) /** Vue.prototype._update* Vue.prototype.$forceUpdate* Vue.prototype.$destroy*/lifecycleMixin(Vue) /** RenderHelpers...* Vue.prototype.$nextTick* Vue.prototype._render*/renderMixin(Vue)
Vue.prototype._init
initLifecycle(vm) // 变量init 并把当前实例添加到parent的$children里initEvents(vm) // _events变量存放事件initRender(vm) //defineReactive $attrs $listenerscallHook(vm, 'beforeCreate') //函数钩子initInjections(vm) // provide 和 inject 主要为高阶插件/组件库提供用例。并不推荐直接用于应用程序代码中。initState(vm) // initProps、initMethods、initData、initComputedinitProvide(vm) // resolve provide after data/propscallHook(vm, 'created')vm.$mount //vm._render -> _update 渲染
声明周期钩子
beforeCreate -> created -> beforeMount -> mounted
参考资料
Vue provide / inject