VUE2.6.10——Vue對象

  • /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 $listeners
callHook(vm, 'beforeCreate')   //函數鉤子
initInjections(vm) // provide 和 inject 主要爲高階插件/組件庫提供用例。並不推薦直接用於應用程序代碼中。
initState(vm)  // initProps、initMethods、initData、initComputed
initProvide(vm) // resolve provide after data/props
callHook(vm, 'created')

vm.$mount  //vm._render -> _update 渲染

聲明週期鉤子

beforeCreate -> created -> beforeMount -> mounted

參考資料

Vue provide / inject

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章