首页 > 解决方案 > FirebaseError:使用无效数据调用函数 Query.where()。不支持的字段值:未定义

问题描述

我只想获取 where 指定的文档。

在新注册时将在 uid 属性中注册的电子邮件地址作为值存储在 Firestore 中。

    async signUp() {
      const db = firebase.firestore();
      await this.$store.dispatch('signUp', { username:this.username, email:this.email, password:this.password });
      await db.collection('myData').doc(this.username).set({
        uid: this.email,
        email: this.email,
        myWallet: 1000
      });
      this.$router.push('/home');
    }
async signUp({ commit }, userInfomation) {
      try {
        await firebase
          .auth()
          .createUserWithEmailAndPassword(
            userInfomation.email,
            userInfomation.password
          );
        const user = firebase.auth().currentUser;
        await user.updateProfile({
          displayName: userInfomation.username,
        });
        commit('setUserName', user);
      } catch (e) {
        alert(e.message);
      }
    },
  mutations: {
    setUserName(state, user) {
      state.userName = user.displayName;
    },
actions: {
async getMyWallet({ commit, state }) {
      const uid = state.updateUserName.email; //Information on the logged-in user is stored in updateUserName.
      const db = firebase.firestore();
      const doc = await db
        .collection('myData')
        .where('uid', '==', uid)
        .get();
      commit('getMyWallet', doc);
    }
}

当我运行它时,我得到了标题中写的错误。

是不是写错了?

有没有其他好办法?

    async getMyWallet({ commit }) {
      firebase.auth().onAuthStateChanged(user => {
        const uid = user.email;
        const db = firebase.firestore();
        const doc = db
          .collection('myData')
          .where('uid', '==', uid)
          .get();
        commit('getMyWallet', doc);
      });
    },

当我重写 getMyWallet 部分时,出现了一个新错误。

错误详情:doc.data 不是函数

标签: javascriptvue.jsgoogle-cloud-firestorevuex

解决方案


推荐阅读