了解可用于在 Expo 项目中存储数据的不同库。
存储数据对于移动应用中实现的功能至关重要。根据你要存储的数据类型和应用的安全要求,可以使用不同的方法在 Expo 项目中保存数据。此页面列出了各种库,可帮助你确定哪种解决方案最适合你的项目。
¥Storing data can be essential to the features implemented in your mobile app. There are different ways to save data in your Expo project depending on the type of data you want to store and the security requirements of your app. This page lists a variety of libraries to help you decide which solution is best for your project.
¥Expo SecureStore
expo-secure-store
提供了一种在设备本地加密和安全存储键值对的方法。
¥expo-secure-store
provides a way to encrypt and securely store key-value pairs locally on the device.
有关如何安装和使用 expo-secure-store 的更多信息,请参阅其 API 文档。
¥Expo FileSystem
expo-file-system
提供对设备本地存储的文件系统的访问。在 Expo Go 中,每个项目都有一个单独的文件系统,并且无法访问其他 Expo 项目的文件。但是,它可以将其他项目共享的内容保存到本地文件系统,并与其他项目共享本地文件。它还能够从网络 URL 上传和下载文件。
¥expo-file-system
provides access to a file system stored locally on the device. Within Expo Go, each project has a separate file system and no access to other Expo projects' files. However, it can save content shared by other projects to the local filesystem and share local files with other projects. It is also capable of uploading and downloading files from network URLs.
有关如何安装和使用 expo-file-system 的更多信息,请参阅其 API 文档。
expo-sqlite
包使你的应用可以访问可通过类似 WebSQL 的 API 进行查询的数据库。数据库在应用重新启动后保留。你可以使用它来导入现有数据库、打开数据库、创建表、插入项目、查询和显示结果以及使用准备好的语句。
¥expo-sqlite
package gives your app access to a database that can be queried through a WebSQL-like API. The database is persisted across restarts of your app. You can use it for importing an existing database, opening databases, creating tables, inserting items, querying and displaying results, and using prepared statements.
有关如何安装和使用 expo-sqlite 的更多信息,请参阅其 API 文档。
¥Async Storage
异步存储 是 React Native 应用的异步、未加密、持久键值存储。它有一个简单的 API,是存储少量数据的不错选择。对于存储不需要加密的数据(例如用户首选项或应用状态)来说,它也是一个不错的选择。
¥Async Storage is an asynchronous, unencrypted, persistent key-value storage for React Native apps. It has a simple API and is a good choice for storing small amounts of data. It is also a good choice for storing data that does not need encryption, such as user preferences or app state.
有关如何安装和使用异步存储的更多信息,请参阅其文档。
¥Other libraries
还有其他库可用于存储不同目的的数据。例如,你的项目可能不需要加密,或者正在寻找类似于异步存储的更快的解决方案。
¥There are other libraries available for storing data for different purposes. For example, you might not need encryption in your project or are looking for a faster solution similar to Async Storage.
我们建议查看 React Native 获取库列表 来帮助你存储项目数据。
¥We recommend checking out React Native for a list of libraries to help you store your project's data.