Vue 无法读取未定义的 属性

Vue cannot read property of undefined

<template>
  <f7-page>
    <f7-navbar>
        <f7-nav-left back-link="Zurück"></f7-nav-left>
        <f7-nav-title>{{groupDetails.data.group.name}}</f7-nav-title>
        <f7-nav-right></f7-nav-right>
    </f7-navbar>
    <f7-list>
        <f7-list-item>{{$f7route.params.groupKey}}</f7-list-item>
        <f7-list-item>{{groupDetails.data.owner.userID}}</f7-list-item>
    </f7-list>
  </f7-page>
</template>
<script>
import *  as firebase from 'firebase'

export default {
    beforeCreate: function() {
        var this_ = this
        firebase.firestore().collection("groups").doc(this_.$f7route.params.groupKey).onSnapshot({
            includeMetadataChanges: true
        }, function(doc) {
            this_.groupDetails = ({data: doc.data()})
            console.log(this_.groupDetails)
        })

    },
    data() {
        return {
            groupDetails: []
        }
    }
}
</script>

我不知道为什么但无法在此页面上导航查看路由器。 "Cannot read property 'group' of undefined"" 这就是错误。

有人知道为什么吗?

groupDetails.data.group 检查为 v-if,以便仅当组存在时才显示模板。这可能是由于异步调用尚未完成。

您可以拨打this.$nextTick

this.$nextTick(()=>{ 
  //some code
});

Defer the callback to be executed after the next DOM update cycle. Use it immediately after you’ve changed some data to wait for the DOM update. https://vuejs.org/v2/api/#Vue-nextTick