02_vue入口


Vue入口文件是 src/platforms/web/entry-runtime-with-compiler.js

你可以从该文件看到

//引入 vue
import Vue from './runtime/index'

//往vue的原型中加入了一个$mount方法
Vue.prototype.$mount = function...
//导出了vue
export default Vue
runtime/index.js
import Vue from 'core/index'

//往Vue中添加了一些配置
Vue.config.mustUseProp = mustUseProp
....

//这段代码有点眼熟
Vue.prototype.$mount = function...


export default Vue
core/index
import Vue from './instance/index'

//初始化全局API
initGlobalAPI(Vue)


Object.defineProperty(Vue.prototy...

export default Vue
./instance/index
//终于找到了Vue的定义
function Vue (options) {   if (process.env.NODE_ENV !== 'production' &&    //Vue必须是通过new的方式来进行创建的     !(this instanceof Vue)   ) {     warn('Vue is a constructor and should be called with the `new` keyword')   }   this._init(options) } //给vue原型定义方法 initMixin(Vue) stateMixin(Vue) eventsMixin(Vue) lifecycleMixin(Vue) renderMixin(Vue)

Vue初始化的时候都做了什么?往Vue原型中定义了一些方法(instance/index.js),往Vue中定义了静态属性(initGlobalAPI(Vue))

相关