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