【发布时间】:2021-11-23 23:49:10
【问题描述】:
我们在 firebase 中有一个 realtimedb,其数据如下:
在我们的 nuxt 页面上,我们有以下方法:
async getDb () {
const messageRef = this.$firebase.database.ref('test')
try {
const snapshot = await messageRef.once('value')
alert(snapshot.val().message)
} catch (e) {
alert(e)
}
},
这是由 this 运行的,如下所示:
mounted () {
this.getDb()
},
我不断收到此错误:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'database')
我做错了吗?我在 Nuxt.config.js 中有所有的 firebase 配置,并且 suth 工作正常。我还将 realtimedb 添加到服务中:
services: {
realtimeDb: true,
auth: {
ssr: true,
// it is recommended to configure either a mutation or action but you can set both
initialize: {
onAuthStateChangedMutation: 'ON_AUTH_STATE_CHANGED_MUTATION'
// onAuthStateChangedAction: 'onAuthStateChangedAction'
}
},
您如何实际访问 realtimedb 中的数据,以便在我的页面上显示测试数组?
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions nuxt.js