【发布时间】:2020-04-19 11:42:55
【问题描述】:
我的目标是从 firebase 实时更新。我需要从 firebase 获得评论并在 this.note 上更新它。在函数 update() 的某个地方我做错了什么。教程一followed.
methods: {
update(){
db.collection("form").onSnapshot((querySnapshot)=>{
this.userdata1=[]
querySnapshot.forEach((doc)=>{
this.userdata1.push(doc.data().comment);
});
});
},
editComment(userDetails) {
$('#commentModal').modal('show');
this.note = userDetails.comment || '';
this.activeuser = userDetails.id;
},
saveComment() {
let id = this.activeuser;
if (!id) {
alert('Fail');
return;
}
db.collection("form")
.doc(this.activeuser)
.update({
comment: this.note
})
.then(() =>{
this.update();
$('#commentModal').modal('hide');
console.log("Document successfully written!");
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
}
}
【问题讨论】:
-
填充数组后,您永远不会对
this.userdata1进行任何操作。 -
正如迈克尔所说,您从 Firebase 获取数据,将其保存在“userdata1”上,然后不使用它,您是否设法调查并检查数据是否确实存在于“用户数据1”? (可能使用 console.log)。
标签: javascript node.js firebase vue.js google-cloud-firestore