Vue的开放API设置顺序

132 阅读1分钟

背景

最近在重新学习vue2源码,上一篇总结了new Vue()之后vue帮我们做的事情,vue的声明周期起始就是实例化vue的代码流程。还有vue的一些在prototype上和Vue上静态属性和方法的设置,故记录下,其中大部分都可以从vue的api中查到。即是vue使用的门面模式对用户暴露的api。

文件的顺序即是api的设置顺序

  1. D:\todos\vue-study\src\core\instance\index.js // vue的构造函数
  2. initMixin src\core\instance\init.js
Vue.prototype._init
  1. stateMixin src\core\instance\state.js
 Object.defineProperty(Vue.prototype, '$data', dataDef)
 Object.defineProperty(Vue.prototype, '$props', propsDef)
 Vue.prototype.$set = set
 Vue.prototype.$delete = del
 Vue.prototype.$watch
  1. eventsMixin src\core\instance\events.js
Vue.prototype.$on
Vue.prototype.$once
Vue.prototype.$off
Vue.prototype.$emit
  1. lifecycleMixin src\core\instance\lifecycle.js
Vue.prototype._update
Vue.prototype.$forceUpdate
Vue.prototype.$destroy
  1. renderMixin src\core\instance\render.js
installRenderHelpers(Vue.prototype);
Vue.prototype.$nextTick
Vue.prototype._render
  1. installRenderHelpers src\core\instance\render-helpers\index.js
    target._o = markOnce
    target._n = toNumber
    target._s = toString
    target._l = renderList
    target._t = renderSlot
    target._q = looseEqual
    target._i = looseIndexOf
    target._m = renderStatic
    target._f = resolveFilter
    target._k = checkKeyCodes
    target._b = bindObjectProps
    target._v = createTextVNode
    target._e = createEmptyVNode
    target._u = resolveScopedSlots
    target._g = bindObjectListeners
    target._d = bindDynamicKeys
    target._p = prependModifier
  1. initGlobalAPI() src\core\global-api\index.js
Object.defineProperty(Vue, 'config', configDef)
Vue.util = {
    warn,
    extend,
    mergeOptions,
    defineReactive
}

Vue.set = set
Vue.delete = del
Vue.nextTick = nextTick
Vue.observable=() => {}
initUse(Vue)
initMixin(Vue)
initExtend(Vue)
initAssetRegisters(Vue)
  1. $mount src\platforms\web\runtime\index.js
Vue.config.mustUseProp = mustUseProp
Vue.config.isReservedTag = isReservedTag
Vue.config.isReservedAttr = isReservedAttr
Vue.config.getTagNamespace = getTagNamespace
Vue.config.isUnknownElement = isUnknownElement

extend(Vue.options.directives, platformDirectives)
extend(Vue.options.components, platformComponents)

Vue.prototype.__patch__ = inBrowser ? patch : noop
Vue.prototype.$mount = () => {
    return mountComponent(this, el, hydrating)
}
  1. compile src\platforms\web\entry-runtime-with-compiler.js
const mount = Vue.prototype.$mount
Vue.prototype.$mount = () => {
    return mount.call(this, el, hydrating)
}
Vue.compile = compileToFunctions