从 vue 更新 firestore,然后重新加载页面以获取更新的数据(不起作用)

Posted

技术标签:

【中文标题】从 vue 更新 firestore,然后重新加载页面以获取更新的数据(不起作用)【英文标题】:Updating firestore from vue, then reload page to get updated data (not working) 【发布时间】:2021-06-29 20:23:12 【问题描述】:

我想:

从我当前的 firestore 中获取一个数组

更新数组

使用新数组更新 firestore

使用新的更新信息重新加载页面。

db.collection("partners").doc(uid).get().then(doc => 
        curarr = doc.data().donation_goal
        curarr[curmonth] = newgoal;
      ).then(() => 
        alert(curarr)
        db.collection("partners").doc(uid).update(
          "donation_goal": curarr
        );
      ).then(() => 
        location.reload(true);
      )

奇怪的是我要注释掉location.reload(true); 并手动刷新页面,它的工作原理。 但是,添加 location.reload(true) 根本不会更新我的数据库。

有没有办法解决这个问题?

【问题讨论】:

【参考方案1】:

我玩过,发现了问题。这是关于我放置 then 子句的地方。

您可以在下面找到更新的答案:

db.collection("partners").doc(uid).get().then(doc => 
    curarr = doc.data().donation_goal
    curarr[curmonth] = newgoal;
    db.collection("partners").doc(uid).update(
        "donation_goal": curarr
    ).then(() => 
        location.reload(true);
    );
)

【讨论】:

以上是关于从 vue 更新 firestore,然后重新加载页面以获取更新的数据(不起作用)的主要内容,如果未能解决你的问题,请参考以下文章

Firestore 在不重新加载应用程序的情况下不更新 SwiftUI 网格

颤振更新文本小部件变量而无需重新加载

尝试搜索 Firestore 并重新加载 tableview 时出现 SearchBar 问题

Vue3:v-model的问题,它不更新组件

firestore onSnapshot 更新值,但不更新 VueJS 中的 DOM

vue更新或者重新加载组件方法