【问题标题】:Realtime update from firebase从 Firebase 实时更新
【发布时间】: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);
    });
}
}

完整代码:https://pastebin.com/tx5F0zz8

【问题讨论】:

  • 填充数组后,您永远不会对this.userdata1 进行任何操作。
  • 正如迈克尔所说,您从 Firebase 获取数据,将其保存在“userdata1”上,然后不使用它,您是否设法调查并检查数据是否确实存在于“用户数据1”? (可能使用 console.log)。

标签: javascript node.js firebase vue.js google-cloud-firestore


【解决方案1】:

您在 4:38 的视频中缺少 watcher() 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多