在模式框内,我有textarea,它从firebase返回“注释”。我的目标是根据评论从firebase进行实时更新。我认为错误可能出在userdata1上,但我不知道如何解决它。教程I followed。 整个代码:https://pastebin.com/tx5F0zz8 答案 0 :(得分:0) 您在4:38的视频中缺少watcher()函数。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);
});
}
}
1 个答案: