【问题标题】:Set a getter into a firestore section of vuefire将 getter 设置到 vuefire 的 firestore 部分
【发布时间】:2021-05-05 02:44:00
【问题描述】:

我正在寻找一种使用 vue 设置从 getter 到 firestore 部分的属性的方法。我正在使用 vuefire,但出现此错误:

vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read property 'getToUid' of undefined

下面是我的代码:

    data: () => ({
      name:'',
    }),
    firestore: () => ({
        // eslint-disable-next-line no-undef
        usersList: db.collection(users),
        dmMessages: db.collection(direct_message).doc(this.getToUid).collection(message_collection_name)
      }),
    computed: {
        ...mapGetters({
          getToUid: "chats/GET_TO_UID",
        }),
    }

getToUid 设置到这一行的最佳方法是什么:

 dmMessages: db.collection(direct_message).doc(this.getToUid).collection(message_collection_name)

【问题讨论】:

    标签: javascript firebase vue.js google-cloud-firestore vuefire


    【解决方案1】:

    您的firestore 选项不应是箭头函数,否则它无法通过this 访问组件实例。将其更改为:

    firestore() {
      return {
        usersList: db.collection(users),
        dmMessages: db.collection(direct_message).doc(this.getToUid).collection(message_collection_name)
      }
    },
    

    【讨论】:

      猜你喜欢
      • 2020-10-20
      • 2021-05-04
      • 2021-05-02
      • 2019-01-05
      • 2020-01-10
      • 2019-10-03
      • 2021-06-01
      • 2021-01-22
      • 1970-01-01
      相关资源
      最近更新 更多