vue 入口
从vue的构建过程可以知道,web环境下,入口文件在 src/platforms/web/entry-runtime-with-compiler.js(以Runtime + Compiler模式构建,vue直接运行在浏览器进行编译工作)
import Vue from './runtime/index'
下一步,找到./runtime/index,发现:
import Vue from 'core/index'
下一步,找到core/index,发现:
import Vue from './instance/index'
按照这个思路找,最后发现:Vue是在'core/index'下定义的
import { initMixin } from './init'
import { stateMixin } from './state'
import { renderMixin } from './render'
import { eventsMixin } from './events'
import { lifecycleMixin } from './lifecycle'
import { warn } from '../util/index'
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)
}
initMixin(Vue)
stateMixin(Vue)
eventsMixin(Vue)
lifecycleMixin(Vue)
renderMixin(Vue)
export default Vue
引入方法,用function定义了Vue类,再以Vue为参数,调用了5个方法,最后导出了vue。
可以进入这5个文件查看相关方法,主要就是在Vue原型上挂载方法,可以看到,Vue 是把这5个方法按功能放入不同的模块中,这很利于代码的维护和管理
initGlobalAPI
回到core/index.js, 看到除了引入已经在原型上挂载方法后的 Vue 外,还导入initGlobalAPI 、 isServerRendering、F