如何在页面上重新加载服务器请求?

时间:2019-06-03 11:26:06

标签: javascript angular

我不会在退出/重新加载页面上保存用户数据:

@HostListener('window:beforeunload', ['$event']) async unloadHandler() {
    await this.api.saveUserSettings(this.userSetting);
}

这有时是工作,有时不是。 在Chrome网络中,我看到请求始终被取消。

1 个答案:

答案 0 :(得分:0)

因为您无法通过非阻止操作阻止用户离开页面。

相反,您应该将设置保存在本地存储中

@HostListener('window:beforeunload', ['$event']) async unloadHandler() {
  localStorage.setItem('settings', this.userSetting);
}

并使用resolverapplication initializer发出请求,在重新加载页面后

相关问题