vue源码解析1:new vue

70 阅读1分钟

vue源码解析1:new vue

  1. 调用new vue
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

2.执行过程(目录在vue>src>instance>index.ts)

import { initMixin } from './init'

function Vue(options) {
  if (__DEV__ && !(this instanceof Vue)) {
    warn('Vue is a constructor and should be called with the `new` keyword')
  }
  this._init(options)
}

initMixin(Vue)

把router,store,render: h => h(App),传入了this._init函数

执行了initMixn方法

3.this._init()是什么(在init.ts文件里)

export function initMixin(Vue: typeof Component) {
    Vue.prototype._init = function (options?: Record<string, any>) {
    }
}    

定义了_init函数,挂载到了vue原型链上

3.this._init()干了什么(下一章解读)