【问题标题】:non AngularJS way of reading $localstorage非 AngularJS 读取 $localstorage 的方式
【发布时间】:2016-03-31 12:40:18
【问题描述】:

所以通常我会使用cookies 将数据从一个AngularJS 应用程序解析到另一个应用程序,然后在bootstrapping 我的应用程序之前读取这些cookie。

这种方法的问题是 cookie 有大小限制。为了解决这个问题,我考虑使用 ngStorage 库中的 $localstorage

现在我的问题是,如何在bootstrapping 我的应用程序之前读取存储在我的$localstorage 中的数据,即:纯JavaScript

【问题讨论】:

  • localStorage.getItem('Key')

标签: javascript angularjs cookies ng-storage


【解决方案1】:

其实很简单:

商店物品:

localStorage.setItem('key', 'value');

获取物品:

localStorage.getItem('key');

您可能希望将 JSON 存储在存储中,因此您始终可以在 set 方法中使用 JSON.stringify(var)JSON.parse(var)在你得到之后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 2020-04-18
    相关资源
    最近更新 更多