gpt4 book ai didi

javascript - Firestore : Unable to read document data (Uncaught TypeError: docSnap. 存在不是 HTMLFormElement 的函数)

转载 作者:行者123 更新时间:2023-12-05 00:43:32 26 4
gpt4 key购买 nike

我是一名新开发人员,没有网络应用方面的经验。我在 Firestore 中有一个名为“用户”的集合,其中文档 ID 是用户的电子邮件。我正在尝试按照 Firebase here 提供的示例读取其中一个文档中的数据

我收到两个错误:

  • 第一个是“await”的使用:Uncaught SyntaxError: Unexpected reserved word
  • 第二个是这条消息:Uncaught TypeError: docSnap.exists is not a function在 HTMLFormElement。

我通过省略“等待”绕过了第一个,但无法避免第二个。你知道我的代码有什么问题吗?

console.log(docSnap) 给出以下消息:“Promise {pending}”

谢谢。

requestForm.addEventListener('submit', (event) => {
event.preventDefault();

const user = auth.currentUser;
const docSnap = await getDoc(doc(db, "users", user.email));

if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
console.log("No such document!");
}
})

最佳答案

看起来您返回了一个 Promise,但它不符合 async/await 的要求。试试这个方法。

getDoc(doc(db, "users", user.email)).then(docSnap => {
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
console.log("No such document!");
}
})

关于javascript - Firestore : Unable to read document data (Uncaught TypeError: docSnap. 存在不是 HTMLFormElement 的函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69530622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com