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