更新阵列项目-Vue / Nuxt和Cloud Firestore

时间:2019-05-31 21:36:05

标签: arrays vue.js firebase-realtime-database google-cloud-firestore nuxt.js

我能够从项目数组中推送和弹出,但是在更新/修改从实时侦听器接收到的数组项目时遇到了问题。

db.collection("packages").onSnapshot(res => {
  const changes = res.docChanges();
  changes.forEach(change => {
    if (change.type === "added") {
      console.log("added");
      this.projects.push({
        ...change.doc.data(),
        id: change.doc.id
      });
    }
    if (change.type === "modified") {
      console.log("modified");
    }
    if (change.type === "removed") {
      console.log("removed");
      this.projects.pop({
        ...change.doc.data(),
        id: change.doc.id
      });
    }
    });
   });

<div v-for="project in projects" :key="project.id"> {{ project.name }} </div>

0 个答案:

没有答案