Remote Service in Aurelia Component Lifecycle

陌路散爱 提交于 2019-12-20 02:28:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!