我有注销功能,对于一个特定的用户,我们需要做一个后端API调用,然后进行从API调用的响应不需要太多的时间,但注销过程需要6-7秒,我正在寻找方法来优化这一点,但找不到任何。以下是我的代码:
if(localStorage['currentUser']=='xyz'){
this.http.post('url', email).subscribe(res => {
localStorage.clear();
this.router.navigate(['login']).then(() => {
this.store.dispatch(new Logout());
})
})
}
任何帮助都是非常感谢的。提前谢谢。
发布于 2021-01-12 11:52:07
不需要创建新的Logout()
,只需要在函数logout()
中使用BehaviorSubject和空值。
authenticate$: Subject<User | ErrorMessages> = new BehaviorSubject<
User | ErrorMessages
>(null);
...
logout(): void {
this.authenticate$.next(null);
this.localStorageService.clearAllCache();
this.router.navigate(['/login']);
}
https://stackoverflow.com/questions/65677340
复制相似问题