通过构建出来的Vue.js在src/platforms/web/entry-runtime-with-compiler.js
这个文件中有引用到类似vue的东西:import Vue from './runtime/index'
下面看一下这个文件:
可以看到文件中又有应用到类似vue的东西:
import Vue from 'core/index'
那我们再继续看看这个文件:
结果一看又是相似的场景:
import Vue from './instance/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
功夫不负有心人,总算是看到的vue的真正的面目了。
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)
}
而剩下的`xxxMixin```主要是对vue原型的一些扩展。
回到上面的core/index文件可以看到引用了./global-api/index
这里就是在 Vue 上扩展的一些全局方法的定义
总结:
core/index文件主要是对vue的初始化
./instance/index中使用了许多xxxMixin对vue原型进行了扩展