initGlobalAPI
Vue.config
在 initGlobalAPI 中初始化,一些全局所需的配置
{optionMergeStrategies: Object.create(null), // 用于合并策略,用于 core/util/optionssilent: false, // 是否取消警告productionTip: process.env.NODE_ENV !== 'production', // 在启动时是否显示生产模式提示消息devtools: process.env.NODE_ENV !== 'production', // 是否启用开发者模式performance: false, // 是否记录性能errorHandler: null, // 用于处理错误的函数warnHandler: null, // 用于处理警告的函数ignoredElements: [], // 忽略哪些自定义元素keyCodes: Object.create(null), // v-on 的自定义别名isReservedTag: no,isReservedAttr: no,isUnknownElement: no,getTagNamespace: noop, // 获取标签的命名空间parsePlatformTagName: identity, // 解析指定平台的真实标签mustUseProp: no, // 检查 attrs 是否必须得用 props 绑定async: true, // 是否开启异步更新_lifecycleHooks: LIFECYCLE_HOOKS}
Vue.util
在 initGlobalAPI 中初始化,应该并不推荐开发者使用,应该主要是给 plugin 开发者使用的,比如 vue-router 等插件所需的工具方法
{warn, // 报错函数extend, // 对象合并函数mergeOptions, // 用于修改 options 值 @link https://juejin.im/post/6844903821903298568defineReactive // 将数据对象的数据属性转换为访问器属性}
Vue.set/Vue.delete/Vue.nextTick
在 initGlobalAPI 中初始化,等同 $set/ $delete / $nextTick ,感觉也是暴露给 plugin 使用的。
Vue.options
在 initGlobalAPI 中使用,组件的全局配置存放的地方
{components: {KeepAlive},directives: Object.create(null),filters: Object.create(null),_base: Vue}
Vue.use
在 initGlobalAPI 中通过 initUse 初始化得到,用于安装 plugin
在此处可以对 Vue 加工
Vue.mixin
在 initGlobalAPI 中通过 initMixin 初始化得到, 用于安装全局 mixin
主要通过 mergeOptions 将 mixin 传入到 Vue.options.mixin 中
Vue.cid/Vue.extend
Vue.component/Vue.directive/Vue.filter
在 initGlobalAPI 中通过 initAssetRegisters 中初始化得到
其实类似于 Vue.mixin 通过 mergeOptions 添加全局的 options
总结
// initGlobalAPIVue.configVue.util = {warn,extend,mergeOptions,defineReactive}Vue.set = setVue.delete = delVue.nextTick = nextTickVue.options = {components: {KeepAlive// Transition 和 TransitionGroup 组件在 runtime/index.js 文件中被添加// Transition,// TransitionGroup},directives: Object.create(null),// 在 runtime/index.js 文件中,为 directives 添加了两个平台化的指令 model 和 show// directives:{// model,// show// },filters: Object.create(null),_base: Vue}// initUse ***************** global-api/use.jsVue.use = function (plugin: Function | Object) {}// initMixin ***************** global-api/mixin.jsVue.mixin = function (mixin: Object) {}// initExtend ***************** global-api/extend.jsVue.cid = 0Vue.extend = function (extendOptions: Object): Function {}// initAssetRegisters ***************** global-api/assets.jsVue.component =Vue.directive =Vue.filter = function (id: string,definition: Function | Object): Function | Object | void {}// expose FunctionalRenderContext for ssr runtime helper installationObject.defineProperty(Vue, 'FunctionalRenderContext', {value: FunctionalRenderContext})Vue.version = '__VERSION__'// entry-runtime-with-compiler.jsVue.compile = compileToFunctions
