tl; dr,与Aurelia一起,如何从视图模型外部调用视图模型中的函数?
我需要对未执行操作(路由更改,服务器请求等)一段时间的用户执行客户端注销.看完这个GitHub的问题,我创建了一个非活动注销视图,视图模型和有纳入我的app.html并在附件我()函数,我开始计时器,并注销用户的时间到期时.
这一切都很好,但我遇到了一个问题,让我觉得所有这一切都是一个巨大的兔子洞.如何从视图模型外部调用我的resetInactivityTimer()函数,是否可以在类中公开调用一个函数?就像执行对服务器的请求一样,我想从我的服务类调用resetInactivityTimer()函数
非活动logout.ts
import {Aurelia} from 'aurelia-framework';
import {Router} from 'aurelia-router';
import {inject} from 'aurelia-dependency-injection';
@inject(Aurelia, Router)
export class InactivityLogout {
inactivityWarningDuration: number; // how long should the warning be up
initialInactivityWarningDuration: number; // how long should the warning be up
inactivityDuration: number; // how long before we warn them
inactivityIntervalHandle: any;
constructor(aurelia, router) {
this.aurelia = aurelia;
this.router = router;
this.initialInactivityWarningDuration = 5;
this.inactivityWarningDuration = this.initialInactivityWarningDuration;
this.inactivityDuration = 5;
}
attached() {
this.queueInactivityTimer();
}
resetInactivityTimer(){ …Run Code Online (Sandbox Code Playgroud)