Skip to main content

数据存储

在 Ionic 应用中,有多种可用的数据存储选项。最好选择最符合你应用需求的选项。一个应用的需求可能涵盖多种存储选项。

🌐 There are a variety of options available for storing data within an Ionic application. It is best to choose options that best fit the needs of your application. A single application may have requirements that span multiple options.

info

某些存储选项涉及第三方插件或产品。在这种情况下,我们既不认可也不支持这些插件或产品。我们在此提及它们仅出于信息用途。

这里是一些常见的使用案例和解决方案:

🌐 Here are some common use cases and solutions:

本地应用设置和数据

🌐 Local Application Settings and Data

许多应用需要在本地存储设置以及其他轻量级的键/值数据。Capacitor Preferences 插件专门用于处理这些场景。

🌐 Many applications need to locally store settings as well as other lightweight key/value data. The Capacitor Preferences plugin is specifically designed to handle these scenarios.

关系型数据存储(仅限移动端)

🌐 Relational Data Storage (Mobile Only)

一些应用,尤其是那些遵循离线优先方法的应用,可能需要在本地存储大量复杂的关系数据。对于这种情况,可以使用 SQLite 插件。最常见的 SQLite 插件有:

🌐 Some applications, especially those following an offline-first methodology, may require locally storing high volumes of complex relational data. For such scenarios, a SQLite plugin may be used. The most common SQLite plugin offerings are:

非关系型高容量数据存储(移动和网页)

🌐 Non-Relational High Volume Data Storage (Mobile and Web)

对于需要存储大量数据并在网页和移动端上运行的应用,一个潜在的解决方案是创建一个键/值对数据存储服务,在网页上使用 indexedDB,在移动端使用前面提到的 SQLite 插件之一。

🌐 For applications that need to store a high volume of data as well as operate on both web and mobile, a potential solution is to create a key/value pair data storage service that uses indexedDB on the web and one of the previously mentioned SQLite plugins on mobile.

这里有一个如何实现这一点的示例:

🌐 Here a sample of how this can be accomplished:

其他选项

🌐 Other Options

还有其他存储选项,它们提供本地和基于云的存储,并且在 Capacitor 应用中表现良好,也可能与你的应用集成良好。

🌐 Other storage options that provide local as well as cloud-based storage that work well within Capacitor applications also exist and may integrate well with your application.

例如:

🌐 For example: