问题
I'm trying to figure out at what point of the component lifecycle do I call into a remote service?
I'm looking to create components that are tied to a remote service so instead of having my remote service be called using the activate callback as part of the screen activation lifecycle, each component would call the remote service themselves. They would show a loading animation until they have received the data from the remote service.
回答1:
Use the attached
callback. When a viewmodel has an attached
method, aurelia will call it after the view has been added to the DOM. Alternatively you could use the bind
callback. It's a bit earlier in the lifecycle than attached
and is called after the component has been data-bound (but is not yet attached to the DOM).
Use the detached
or unbind
methods to cleanup/unsubscribe/cancel any async processes or subscriptions you might have made in attached
or bind
.
created(view)
>> bind(bindingContext)
>> attached()
>> detached()
>> unbind()
来源:https://stackoverflow.com/questions/35489802/remote-service-in-aurelia-component-lifecycle