Javascript Firestore不工作似乎脱机工作
我正在尝试使用firestore创建一个渐进式web应用程序。网络应用程序在计算机联机时正常工作,但在脱机时不工作 我已启用firestore脱机持久性,如下所示-Javascript Firestore不工作似乎脱机工作,javascript,firebase,google-cloud-firestore,progressive-web-apps,Javascript,Firebase,Google Cloud Firestore,Progressive Web Apps,我正在尝试使用firestore创建一个渐进式web应用程序。网络应用程序在计算机联机时正常工作,但在脱机时不工作 我已启用firestore脱机持久性,如下所示- firebase.firestore().settings({ timestampsInSnapshots: true }); firebase.firestore().enablePersistence().then(() => { this.db = firebase.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.
我知道这两个错误在技术上都是正确的。但是这些错误不应该因为我启用了脱机持久性而发生吗
获取脱机数据:如果在设备脱机时获取文档,
云Firestore从缓存返回数据。如果缓存没有
包含该文档的数据,或者该文档不存在
get调用返回一个错误
查询脱机数据:查询与脱机持久性一起工作。你可以
使用直接get或by检索查询结果
听,如前几节所述。您还可以创建
设备脱机时对本地持久化数据的新查询,但
查询最初将仅针对缓存的文档运行
离线持久性并不意味着您的客户可以在没有互联网的情况下与Firestore通信,它意味着,例如,一旦再次发生互联网连接,他所做的更改将提交到相关文档
考虑缓存相关文件,以便用户在一定程度上脱机使用PWA