前端框架Aurelia——元件Component(二)元件生命週期
阿新 • • 發佈:2019-01-10
constructor()
- The view-model's constructor is called first.- created(owningView: View, myView: View)
If the view-model has a
bind
callback,
it will be invoked at this time.
The
"binding context" to which the component is being bound will be passed first.
An
"override context" will be passed second. 4.
attached()
- Next, the component is attached to the DOM (in document).attached
callback,
it will be invoked at this time
元件新增到DOM上
5.detached()
At some point in the future, the component may be removed from the DOM.
If/When
this happens, and if the view-model has a detached
callback,
this is when it will be invoked.
如果元件被從DOM上移出且元件有這個方法,那麼這個方法將被呼叫。unbind
callback,
it will be invoked during this process.
detached()方法後才是unbind()方法。先分離後取消繫結。
unbind會直接開始改變view,detached肯定在unbind前面,首先要從DOM上面移出。
Each
of these callbacks is optional.這些回撥都是可選的。 if you implement
bind
you
will need to implement unbind
.
The
same goes for attached
and detached
,
but again, it isn't mandatory.通常。bind和unbind(), attached和detached方法是一對寫入,但不是強制。 It is important to note that if you implement the
bind
callback
function,
then
the property changed callbacks for any bindable
properties
will not be called when the property value is initially set.
The
changed callback will be called for any subsequent time the bound value changes.意思是初始化的時候屬性被初始化不會呼叫繫結的回撥函式,只有在後面的時候屬性改變才會呼叫回撥。