【问题标题】:How to make a firebase cloud onUpdate function to work properly?如何使 Firebase 云 onUpdate 功能正常工作?
【发布时间】:2018-10-02 13:06:54
【问题描述】:

我在应用程序中添加和输出 cmets。

这应该可以实时运行。

在我的评论组件中,哪个是静态组件,我有完整的逻辑来获取数据并保存在 firebase 中。

现在我想在这里添加一个 onUpdate fb 云功能。

我尝试了下一个方法,但不起作用:

const onCommentsAdded = this.runtime.fb.ref('/comments').onUpdate((change) => {
  const after = change.after;
  console.log('This is after: ', after, change.after)
})

应用程序无法编译,这是错误

未处理的拒绝 (TypeError):runtime.fb.ref(...).onUpdate 不是 功能

【问题讨论】:

    标签: javascript reactjs firebase


    【解决方案1】:

    假设您在 Firebase 而不是 Firestore 上查看 Realtime Database

    您尝试访问的库看起来不正确。请参阅Database Events 文档。

    const onCommentsAdded = functions.database.ref('/comments')
      .onUpdate((change, _context) => {
        const after = change.after;
        console.log('This is after: ', after, change.after)
       });
    

    尝试更新函数以使用functions.database.ref 而不是this.runtime.fb.ref

    【讨论】:

    猜你喜欢
    • 2020-05-18
    • 2020-02-15
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    • 2020-07-04
    • 1970-01-01
    • 2020-10-20
    相关资源
    最近更新 更多