初始化組件
1.流程圖
2.組件初始化
vue.js
function Vue (options) {
this._init(options)//調(diào)用instance/init.js 進(jìn)行初始化工作
}
instance/init.js
_init = function (options) {
options = options || {}
//省略一部分代碼
//合并初始化參數(shù)
options = this.$options = mergeOptions(
this.constructor.options,
options,
this
)
this._data = {} //數(shù)據(jù) module
this._initScope();//初始化作用域
this._initEvents();//初始化事件
this._callHook('created')//
//如果傳入節(jié)點(diǎn)
if (options.el) {
this.$mount(options.el)
}
}
instance/scope.js
初始化作用域
_initScope = function () {
this._initProps()//
this._initMeta();
this._initMethods()
this._initData()//數(shù)據(jù)填充
this._initComputed()//
}
3.數(shù)據(jù)填充