我用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();
}你能帮帮我吗?
发布于 2017-07-13 09:54:15
您可能希望尝试对组件使用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!');
}
}与原始代码片段相比,有一些更改:
activate()的用法在Aurelia的组件生命周期部分中也有更详细的描述。
更新:对于奥雷利亚生命周期的不同,StackOverflow问题Aurelia中组件和视图之间的区别(以及它们的生命周期)可能也很感兴趣。
https://stackoverflow.com/questions/45076400
复制相似问题