vue源码解析
Vue定义全局属性
// core/global-api/index.js
export function initGlobalAPI (Vue: GlobalAPI) {
// config
const configDef = {}
configDef.get = () => config
if (process.env.NODE_ENV !== 'production') {
configDef.set = () => {
warn(
'Do not replace the Vue.config object, set individual fields instead.'
)
}
}
// 定义config全局属性
Object.defineProperty(Vue, 'config', configDef)
// exposed util methods.
// NOTE: these are not considered part of the public API - avoid relying on
// them unless you are aware of the risk.
Vue.util = {
warn,
extend,
mergeOptions,
defineReactive
}
// 定义全局属性
Vue.set = set
Vue.delete = del
Vue.nextTick = nextTick
// 定义observable全局方法
Vue.observable = <T>(obj: T): T => {
observe(obj)
return obj
}
//定义options全局属性,options对象定义了components、directives、filter属性
Vue.options = Object.create(null)
ASSET_TYPES.forEach(type => {
Vue.options[type + 's'] = Object.create(null)
})
// this is used to identify the "base" constructor to extend all plain-object
// components with in Weex's multi-instance scenarios.
Vue.options._base = Vue
// 把内置组件keep-alive的属性混合到Vue.options.components
extend(Vue.options.components, builtInComponents)
// 定义全局use、mixin、extend、
initUse(Vue)
initMixin(Vue)
initExtend(Vue)
initAssetRegisters(Vue)
}全局方法use
全局方法mixin
全局方法extend
定义全局component, directive, filter方法
Vue实例化
Vue构造函数
mergeOptions 函数
mergeOptions 函数resolveConstructorOptions
resolveConstructorOptions如果是组件,执行此函数
初始化Vue生命周期相关属性
初始化Vue父组件为当前组件注册的事件监听器
初始化事件监听器对象
add remove方法
add remove方法把$attrs $listeners转化为响应式数据
$attrs $listeners转化为响应式数据初始化state
响应式原理
依赖类
开始渲染组件
Watcher类
stateMixin()
stateMixin()Last updated