繁体   English   中英

Aurelia激活功能永远不会被调用

[英]Aurelia activate function never be called

我使用Aurelia + WebStorm编写了一个工具栏。 在此工具栏中,有一个激活功能,但永远不会自动调用它。 您可以在此处查看TypeScript代码:

import {autoinject} from "aurelia-dependency-injection";
import {RouteConfig, Router} from "aurelia-router";
import {bindable} from "aurelia-templating";
import {getLogger} from "aurelia-logging";
import {ActuatorApi, NotificationApi, SystemApi} from "gen/api";

@autoinject
export class HeaderBar {
  private static LOG = getLogger("header-bar");
  public notificationKey: string;
  ...

  @bindable
  public router: Router;
  constructor(private actuatorApi: ActuatorApi, private notificationApi: NotificationApi,
              private systemApi: SystemApi) {
      this.isBatterieTestActive = true;
      this.hrefForActuatoresList = "#/app/configuration/actuators/";
      this.loadActuators();
  }

  public async activate(params: any, routeConfig: RouteConfig): Promise<void> {

    return this.loadNotifications();
  }

请你帮助我好吗?

您可能要尝试对组件而不是附加组件使用Activate方法。 例如:

export class HeaderBar {

    private async attached(): Promise<void> {
        return await this.loadNotifications();
    }

    private loadNotifications() {
        // do your async stuff here...
        console.log('yeej, it works!');
    }

}

与原始代码段相比,有一些变化:

  • 考虑到您没有使用params和/或routeconfig,使用Activate似乎是合理的,并且似乎可以满足您的需求(据我所知)
  • 为了简洁起见,我删除了所有其他与您的问题无关的代码
  • 您可以在我的示例中看到,“异步”此方法没问题

在Aurelia文档的“ 组件生命周期”部分中还更全面地描述了activate()的用法。

更新:对于Aurelia生命周期中的差异,StackOverflow问题 Aurelia中的组件和视图之间的差异(及其生命周期)”也可能引起关注。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM