initGlobalAPI
Vue.config
在 initGlobalAPI
中初始化,一些全局所需的配置
{
optionMergeStrategies: Object.create(null), // 用于合并策略,用于 core/util/options
silent: 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/6844903821903298568
defineReactive // 将数据对象的数据属性转换为访问器属性
}
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
总结
// initGlobalAPI
Vue.config
Vue.util = {
warn,
extend,
mergeOptions,
defineReactive
}
Vue.set = set
Vue.delete = del
Vue.nextTick = nextTick
Vue.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.js
Vue.use = function (plugin: Function | Object) {}
// initMixin ***************** global-api/mixin.js
Vue.mixin = function (mixin: Object) {}
// initExtend ***************** global-api/extend.js
Vue.cid = 0
Vue.extend = function (extendOptions: Object): Function {}
// initAssetRegisters ***************** global-api/assets.js
Vue.component =
Vue.directive =
Vue.filter = function (
id: string,
definition: Function | Object
): Function | Object | void {}
// expose FunctionalRenderContext for ssr runtime helper installation
Object.defineProperty(Vue, 'FunctionalRenderContext', {
value: FunctionalRenderContext
})
Vue.version = '__VERSION__'
// entry-runtime-with-compiler.js
Vue.compile = compileToFunctions