javascript - 从 Firebase 实时更新
问题描述
我的目标是从 firebase 实时更新。我需要从 firebase 获得评论并在 this.note 上更新它。在函数 update() 的某个地方我做错了。我遵循的教程。
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);
});
}
}
解决方案
您错过了 4:38 视频中的 watcher() 函数。
推荐阅读
- javascript - 使用 jQuery 复制字段
- angular - 将所有用户从 firebase 获取到自己的后端
- python-3.x - 日期数组到轴单位的 Matplotlib 转换失败
- c - 尝试同时打开多个文件以从中读取时出现分段错误(核心转储)
- jquery - 如何在不刷新页面的情况下使用 django-crispy-forms 实现引导模式表单
- python-3.x - Tensorflow 在进行预测时卡在 sess.run() 中
- android - RecyclerView:没有附加适配器;使用 android socket io 跳过布局
- python - 使用 Doc2Vec 进行情感分类
- python - Pygame移动加速问题,平台游戏
- vue.js - Nuxt js应用程序无故冻结