【问题标题】:getCollections is not a function from inside my Vuex Store [duplicate]getCollections 不是我的 Vuex Store 中的一个函数 [重复]
【发布时间】:2019-10-25 09:33:08
【问题描述】:

我正在尝试从我遇到的某个用户的每个集合的子集合中获取文档。我有一个存储操作,它首先获取列表,然后在 forEach 循环中传递给第二个操作以构建状态。但是当它执行该操作时,我收到一个错误,即 getCollections 不是函数。

getCollections 有什么变化还是我的代码有问题?

谢谢

      // ###########################################
      // ############# Lists #######################

      async usersLists({ commit, state }) {
        let listsData = [];
        // Check if a user is logged in.
        if (state.user) {
          await db
            .collection('lists')
            .where('list_owner', '==', state.user.uid)
            .get()
            .then(querySnapshot => {
              querySnapshot.forEach(doc => {
                listsData.push({
                  id: doc.id,
                  ...doc
                });
                // Commit the state.list.id and pass off to getListAddons
                console.log('setListId: ', doc.id);
                this.commit('setListId', doc.id);
                this.dispatch('getListAddons');
              });
              commit('usersLists', listsData);
            })
            .catch(err => {
              console.log('Error getting documents', err);
            });
        } else {
          commit('usersLists', null);
        }
      },
      async getListAddons({ commit, state, dispatch }) {
        console.log('state of listid: ', state.setListId);
        await db
          .collection('link')
          .doc(state.setListId)
          .getCollections()
          .then(collections => {
            collections.forEach(collection => {
              console.log('Found subcollection with id:', collection.id);
            });
          })
          .catch(err => {
            console.log('Error getting documents', err);
          });
      }

【问题讨论】:

    标签: javascript google-cloud-firestore vuex nuxt.js


    【解决方案1】:

    什么都没有改变。 Cloud Firestore 客户端 SDK 中没有可用的 getCollections()。查看用于 JavaScript 客户端的 DocumentReference 是如何没有列出的。它仅在服务器 SDK 中可用,例如,in the node.js SDK

    【讨论】:

      【解决方案2】:

      根据文档getCollections 尚不支持网络客户端 ,也许您想将其移至可调用函数? :)

      来源:the docs

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-23
        • 2020-10-09
        • 2021-12-13
        • 2014-02-03
        • 1970-01-01
        相关资源
        最近更新 更多