gpt4 book ai didi

javascript - localStorage和ionic 2中的Storage哪个更好?

转载 作者:行者123 更新时间:2023-11-29 17:50:31 26 4
gpt4 key购买 nike

我想将我的验证码存储在本地存储中,ionic2提供了自己的存储模块ionic/storage

storage.set(key,value),
storage.get(key).then(value=> {
console.log(value);
})

但我也尝试过像这样存储,当我在浏览器中测试应用程序时它可以工作。

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

有人可以向我解释哪种是使用本地存储的更好方法吗?为什么?

最佳答案

Ionic 的存储肯定更好。正如您在 docs 中看到的那样:

Storage is an easy way to store key/value pairs and JSON objects. Storage uses a variety of storage engines underneath, picking the best one available depending on the platform.

When running in a native app context, Storage will prioritize using SQLite, as it's one of the most stable and widely used file-based databases, and avoids some of the pitfalls of things like localstorage and IndexedDB, such as the OS deciding to clear out such data in low disk-space situations.

When running in the web or as a Progressive Web App, Storage will attempt to use IndexedDB, WebSQL, and localstorage, in that order.

所以基本上,Ionic 的存储将尝试使用最佳的可用选项,而您甚至不用担心这一点。在 docs您还可以了解如何在项目中安装 SQLite,这将允许 Ionic 的存储使用它,并且是在应用程序中存储信息的最佳方式。

关于javascript - localStorage和ionic 2中的Storage哪个更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44213645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com