存储数据

编辑页面

了解可用于在 Expo 项目中存储数据的不同库。


For the complete documentation index, see llms.txt. Use this file to discover all available pages.

存储数据对于您移动应用中实现的功能可能至关重要。根据您要存储的数据类型以及应用的安全性要求,在 Expo 项目中有不同的保存数据方式。本页列出了一系列库,帮助您决定哪种方案最适合您的项目。

Expo SecureStore

expo-secure-store 提供了一种在设备本地加密并安全存储键值对的方法。它适用于令牌、密钥以及其他机密等较小的值。

Icon
Expo SecureStore API 参考

有关如何安装和使用 expo-secure-store 的更多信息,请参阅其 API 文档。

Expo FileSystem

expo-file-system provides access to the file system stored locally on the device. In Expo Go, each project has a separate file system and cannot access files from other Expo projects. However, it can save content shared by other projects to the local file system, and share local files with other projects. It can also upload and download files from network URLs.

Icon
Expo FileSystem API 参考

有关如何安装和使用 expo-file-system 的更多信息,请参阅其 API 文档。

Expo SQLite

expo-sqlite 包让您的应用可以访问一个可通过类似 WebSQL 的 API 进行查询的数据库。该数据库会在应用重启后保持持久化。您可以用它导入现有数据库、打开数据库、创建表、插入项目、查询并展示结果,以及使用预编译语句。

Icon
Expo SQLite API 参考

有关如何安装和使用 expo-sqlite 的更多信息,请参阅其 API 文档。

Async Storage

Async Storage 是一种异步、未加密、持久化的键值存储,适用于 React Native 应用。它具有简单的 API,是存储少量数据的不错选择。它也适合存储不需要加密的数据,例如用户偏好设置或应用状态。

Async Storage 文档

有关如何安装和使用 Async Storage 的更多信息,请参阅其文档。

其他库

还有其他可用于不同用途的数据存储库。例如,您可能不需要项目中的加密,或者正在寻找类似于 Async Storage 的更快解决方案。

我们建议查看 React Native 的库列表,以帮助您存储项目的数据。