【问题标题】:How to optimize logout in Angular 6?如何在 Angular 6 中优化注销?
【发布时间】:2021-04-17 00:20:42
【问题描述】:

我有注销功能,对于特定用户,我们需要进行后端 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());
            })
          })
}

非常感谢任何帮助。提前致谢。

【问题讨论】:

    标签: javascript angular typescript angular6 logout


    【解决方案1】:

    不要新建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']);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-05-19
      • 2019-04-13
      • 2019-11-12
      • 2023-01-26
      • 1970-01-01
      • 2016-10-21
      • 1970-01-01
      • 2019-04-01
      • 2020-08-14
      相关资源
      最近更新 更多