firestore部分的访问方法-vuefire

Access method in the firestore section - vuefire

我正在尝试访问 vuefire 的 firestore 部分中的方法,但出现此错误:

vue-router.esm.js?8c4f:2257 TypeError: Cannot read property 'messagesWith' of undefined
    at eval (Chat.vue?62f3:214)

这是发生错误的行:

parents: this.messagesWith(db.auth().currentUser.uid),

下面是我的完整代码:

export default {
  data: () => ({

    activeChat: undefined,
    parents: [],
    messages: [],
    messageForm: {
      content: "",
      me: true,
      createdAt: new Date()
    }
  }),
  firestore: {
    // eslint-disable-next-line no-undef
    messages: db.collection(message_collection_name).orderBy('createdAt','asc'),
    parents: this.messagesWith(db.auth().currentUser.uid),
  },
  computed: {
    
  },
  methods:{
    
    dmCollection(toUid){
      const idPair = [db.auth().currentUser.uid, toUid].join('_').sort();
      return db.firestore().collection(direct_message).doc(idPair).collection(message_collection_name);
    },
    sendDm(toUid, messageText){
      return this.dmCollection(toUid).add({
        from: db.auth().currentUser.uid,
        message: messageText,
        sent: db.firestore.FieldValue.serverTimestamp()
      })
    },
    messagesWith(uid){
      return this.dmCollection(uid).orderBy('sent', 'desc').get();
    },
    
  },
}

为了访问本地 options/methods 将 firestore 定义为 returns 一个对象的函数 :

  firestore:()=> ({
    // eslint-disable-next-line no-undef
    messages: db.collection(message_collection_name).orderBy('createdAt','asc'),
    parents: this.messagesWith(db.auth().currentUser.uid),
  }),