在 Angular 2 中保留页面重新加载的数据 [英] Retain data on page reload in Angular 2
问题描述
在我的 Angular 2 应用程序中,我将一些数据从 HomeComponent 传递到 PageComponent,然后将其保存到 PageComponent 内的变量中.现在,当我刷新页面时,我需要保留这些数据.目前我正在使用会话存储,但我想知道是否有更好的方法来实现这一点.
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. 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.
- 本地存储
- 饼干
- 会话
区别和重要性:如何将令牌存储在 Angular 2 中的本地或会话存储中?
这篇关于在 Angular 2 中保留页面重新加载的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!