1.在new Vue()
的时候,vue\src\core\instance\
里面的_init()
初始化各个功能
function Vue (options) {
if (.NODE_ENV !== 'production' &&
!(this instanceof Vue)
) {
warn('Vue is a constructor and should be called with the `new` keyword')
}
this._init(options) //初始化各个功能
}
2.在_init()
中有这样的一个执行顺序:其中initState()
是在beforeCreate
和created
之间
initLifecycle(vm)
initEvents(vm)
initRender(vm)
callHook(vm, 'beforeCreate')
initInjections(vm) // resolve injections before data/props
initState(vm) //初始化
initProvide(vm) // resolve provide after data/props
callHook(vm, 'created')
3.在initState()做了这些事情:
if () initProps(vm, )//初始化Props
if () initMethods(vm, )//初始化methods
if () {
initData(vm)} else {
observe(vm._data = {}, true /* asRootData */)}//初始化data
if () initComputed(vm, )//初始化computed
4.所以Props
,methods
,data
和computed
的初始化都是在beforeCreated
和created
之间完成的。
参考资料:/q/1010000010364198
end