主要相关文件:instance/index.js、instance/init.js、instance/state.js、instance/events.js、instance/lifecycle.js、instance/
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)
initMixin
- 安装 Vue 初始化函数
_init
stateMinxin
eventMinxin
lifecycleMixin
- 安装视图更新函数
_update - 安装生命周期相关的实例方法
$forceUpdate[$destroy](https://cn.vuejs.org/v2/api/#vm-destroy)
renderMixin
利用
installRenderHelpers安装了运行时所需的工具函数Vue.prototype._o = markOnceVue.prototype._n = toNumberVue.prototype._s = toStringVue.prototype._l = renderListVue.prototype._t = renderSlotVue.prototype._q = looseEqualVue.prototype._i = looseIndexOfVue.prototype._m = renderStaticVue.prototype._f = resolveFilterVue.prototype._k = checkKeyCodesVue.prototype._b = bindObjectPropsVue.prototype._v = createTextVNodeVue.prototype._e = createEmptyVNodeVue.prototype._u = resolveScopedSlotsVue.prototype._g = bindObjectListeners
安装渲染所需的实例函数
$nextTick_render
总结
// initMixin(Vue) src/core/instance/init.js **************************************************Vue.prototype._init = function (options?: Object) {}// stateMixin(Vue) src/core/instance/state.js **************************************************Vue.prototype.$dataVue.prototype.$propsVue.prototype.$set = setVue.prototype.$delete = delVue.prototype.$watch = function (expOrFn: string | Function,cb: any,options?: Object): Function {}// eventsMixin(Vue) src/core/instance/events.js **************************************************Vue.prototype.$on = function (event: string | Array<string>, fn: Function): Component {}Vue.prototype.$once = function (event: string, fn: Function): Component {}Vue.prototype.$off = function (event?: string | Array<string>, fn?: Function): Component {}Vue.prototype.$emit = function (event: string): Component {}// lifecycleMixin(Vue) src/core/instance/lifecycle.js **************************************************Vue.prototype._update = function (vnode: VNode, hydrating?: boolean) {}Vue.prototype.$forceUpdate = function () {}Vue.prototype.$destroy = function () {}// renderMixin(Vue) src/core/instance/render.js **************************************************// installRenderHelpers 函数中Vue.prototype._o = markOnceVue.prototype._n = toNumberVue.prototype._s = toStringVue.prototype._l = renderListVue.prototype._t = renderSlotVue.prototype._q = looseEqualVue.prototype._i = looseIndexOfVue.prototype._m = renderStaticVue.prototype._f = resolveFilterVue.prototype._k = checkKeyCodesVue.prototype._b = bindObjectPropsVue.prototype._v = createTextVNodeVue.prototype._e = createEmptyVNodeVue.prototype._u = resolveScopedSlotsVue.prototype._g = bindObjectListenersVue.prototype.$nextTick = function (fn: Function) {}Vue.prototype._render = function (): VNode {}// core/index.js 文件中Object.defineProperty(Vue.prototype, '$isServer', {get: isServerRendering})Object.defineProperty(Vue.prototype, '$ssrContext', {get () {/* istanbul ignore next */return this.$vnode && this.$vnode.ssrContext}})// 在 runtime/index.js 文件中Vue.prototype.__patch__ = inBrowser ? patch : noopVue.prototype.$mount = function (el?: string | Element,hydrating?: boolean): Component {el = el && inBrowser ? query(el) : undefinedreturn mountComponent(this, el, hydrating)}// 在入口文件 entry-runtime-with-compiler.js 中重写了 Vue.prototype.$mount 方法Vue.prototype.$mount = function (el?: string | Element,hydrating?: boolean): Component {// ... 函数体}
