我用vuejs做了一个应用,顺便说一下,这个应用很不错,它使用了一个本地持久性的firebase auth,还有一个启用了持久性的firestore数据库,一切看起来都很好,我决定用它做一个PWA,这样人们就可以离线使用它,资产是从缓存中加载的,我有安装横幅,我的问题是firestore的持久性不能正常工作。
问题1:离线时,当我插入一个成员到firestore的 "成员 "集合时,用户界面不刷新(一旦我回到网上,用户在列表中,所以持久性工作部分)。
问题2:成员列表。当离线时,应用程序无法访问 "成员 "集合的持久化版本。
这个列表在应用加载的时候是加载的,但是刷新之后,它就消失了.有什么最好的方法来实现这个问题呢?谢谢你的帮助。
我终于找到了一个解决方案:我创建了一个方法。
realtimeListenerMembres() {
// real-time listener
let self = this;
this.$firebase
.firestore()
.collection("membres")
.onSnapshot((snapshot) => {
//console.log(snapshot.docChanges());
snapshot.docChanges().forEach((change) => {
if (change.type === "added") {
self.membres.push({
...change.doc.data(),
id: change.doc.id,
});
}
if (change.type === "removed") {
// remove the document data from the web page
}
self.sendToGroupe();
});
});
我把cal放在 "创建 "循环中。
created() {
this.realitimeListenerGroupe();
this.realtimeListenerMembres();
this.realtimeListenerReunions();
},
现在persistense是确定的assets和fistore.The Pwa可以工作完全离线,然后与fistore同步时,互联网连接回去。