Aurelia 组件生命周期中的远程服务 [英] Remote Service in Aurelia Component Lifecycle

查看:45
本文介绍了Aurelia 组件生命周期中的远程服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚我在组件生命周期的哪个时刻调用远程服务?

I'm trying to figure out at what point of the component lifecycle do I call into a remote service?

我希望创建与远程服务相关联的组件,这样每个组件将自己调用远程服务,而不是使用 activate 回调作为屏幕激活生命周期的一部分来调用我的远程服务.他们会显示加载动画,直到他们收到来自远程服务的数据.

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.

推荐答案

使用 attached 回调.当视图模型具有 attached 方法时,aurelia 将在视图添加到 DOM 后调用它.或者,您可以使用 bind 回调.它在生命周期中比 attached 早一点,并且在组件被数据绑定(但尚未附加到 DOM)之后被调用.

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).

使用 detachedunbind 方法来清理/取消订阅/取消您可能在 attached 中进行的任何异步进程或订阅>绑定.

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()

created(view) >> bind(bindingContext) >> attached() >> detached() >> unbind()

这篇关于Aurelia 组件生命周期中的远程服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆