简体   繁体   English

在Angular 2中保留页面重新加载的数据

[英]Retain data on page reload in Angular 2

In my Angular 2 app, I pass in some data to a PageComponent from my HomeComponent which is then saved to a variable inside the PageComponent. 在我的Angular 2应用程序中,我将一些数据从我的HomeComponent传递给PageComponent,然后将其保存到PageComponent内的变量中。 Now when I refresh the page I need this data to be retained. 现在当我刷新页面时,我需要保留这些数据。 Currently I am using session storage, but I was wondering if there is a better way to implement this. 目前我正在使用会话存储,但我想知道是否有更好的方法来实现它。

Nope, There isn't a other way in this context. 不,在这种情况下没有其他办法。 Once you refresh all the temporary memory is gone. 一旦刷新所有临时内存就不见了。 As you said you are performing session-storage. 正如您所说,您正在执行会话存储。 You may continue with that. 你可以继续这样做。 You may choose the below. 您可以选择以下内容。

  1. LocalStorage localStorage的
  2. Cookie 曲奇饼
  3. Session 会议

Difference and importance: How to store token in Local or Session Storage in Angular 2? 差异和重要性: 如何在Angular 2中的本地或会话存储中存储令牌?

我强烈建议你实现一些服务器端框架并实现数据库并以这种方式存储和检索数据,它更清洁,更可靠,会话是一种非常过时的做事方式,至少我会使用cookie,所以他们在至少坚持得更可靠一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM