gpt4 book ai didi

javascript - Firestore 无法工作 似乎可以离线工作

转载 作者:行者123 更新时间:2023-12-03 00:53:40 25 4
gpt4 key购买 nike

我正在尝试使用 firestore 创建一个渐进式网络应用程序。当计算机在线时,网络应用程序可以正常工作,但在离线时则无法工作。

我已经启用了 firestore 离线持久性,如下所示-

firebase.firestore().settings({ timestampsInSnapshots: true });
firebase.firestore().enablePersistence().then(() => {
this.db = firebase.firestore();
});

如果我在计算机离线时运行该应用程序,则会收到以下错误。

[2018-10-23T07:15:24.406Z]  @firebase/firestore: Firestore (5.5.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

尝试从 firestore 数据库获取文档失败并出现错误

Uncaught (in promise) Error: Failed to get document because the client is offline.

我知道这两个错误在技术上都是正确的。但这些错误不是应该因为我启用了离线持久化而不会发生吗?

最佳答案

Get offline data: If you get a document while the device is offline, Cloud Firestore returns data from the cache. If the cache does not contain data for that document, or the document does not exist, the get call returns an error.

Query offline data: Querying works with offline persistence. You can retrieve the results of queries with either a direct get or by listening, as described in the preceding sections. You can also create new queries on locally persisted data while the device is offline, but the queries will initially run only against the cached documents.

离线持久性并不意味着您的客户可以在没有互联网的情况下与 Firestore 进行通信,这意味着一旦再次出现互联网连接,他所做的更改就会提交到相关文档。

考虑缓存相关文件,以便用户在一定程度上离线使用 PWA。

More info about using it Offline

关于javascript - Firestore 无法工作 似乎可以离线工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52944048/

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