Skip to content
New issue

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

Vue源码阅读笔记 - this._init方法 #26

Open
Jmingzi opened this issue Mar 11, 2018 · 0 comments
Open

Vue源码阅读笔记 - this._init方法 #26

Jmingzi opened this issue Mar 11, 2018 · 0 comments

Comments

@Jmingzi
Copy link
Owner

Jmingzi commented Mar 11, 2018

// 伪代码

let uid = 0

Vue.prototype._init = function(options) {
  const vm = this
  // 
  vm._uid = uid++
  // a flag to avoid this being observed
  vm._isVue = true
    
  // merge options
  if (options && options._isComponent) {
    
  }

  // 
  if (dev) {
    initProxy(vm)
  } else {
    // 含义?
    vm._renderProxy = vm
  }

  vm._self = vm
  
  // 初始化生命周期
  // $parent $root  $children $refs 
  // _watcher _inactive _directInactive 
  // _isMounted _isDestroyed _isBeingDestroyed
  initLifecycle(vm)

  // 绑定事件
  // 为什么是 init parent attached events
  // 即 vm.$options._parentListeners
  initEvents(vm)

  // $slots $scopedSlots
  // _c $createElement
  // 绑定attrs和listeners
  initRender(vm)
  
  // 在调用生命周期钩子时,是可以调用多次
  // handlers[i].call(vm)
  callHook(vm, 'beforeCreate')

  // 
  initInjections(vm)

  // 初始化props、data、methods、computed
  // 如果定义了watch,也初始化watch
  // 其中有observe(value)
  initState(vm)

  // 
  callHook(vm, 'created')

  // 如果el存在
  vm.$mount(vm.$options.el)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant