【发布时间】:2018-11-26 12:33:04
【问题描述】:
随着我对使用 vue 的 Firebase 的了解不断加深,我发现让 html 从 firebase 更新其值变得异常困难。
如果我想在使用后获得单个值
this.$firebaseRefs.Team_Counter.child('numOfTeam').once("value", function(snapshot){
Team_number = snapshot.val();
});
当值没有更新并且需要更改时,这很好。
但我试图获取一个一直在更新并且在 html 中的值
<p>{{Team_Num}}</p>
它会更新一次,如果我重新加载项目,它会再次更新,但在运行时它不会改变值。
我尝试使用一个监听孩子变化的函数
this.$firebaseRefs.Team_Counter.child('numOfTeam').on("child_changed", function(snapshot){
Team_number = snapshot.val();
} );
但我得到的结果与上面的代码相同。
正在使用
on.("child_changed" ...)
解决这个问题的正确方法是什么?还是我错过了其他东西?在读取更改后的数据之前,是否需要向该值添加其他内容?
谢谢
【问题讨论】:
标签: javascript firebase firebase-realtime-database vue.js