我希望我可以包含完整的代码。不然很难理解我的问题。
\n我为我的 Vue 应用程序创建了一个可组合函数,其目的是从数据库中获取文档集合。\n可组合函数如下所示:
\nimport { ref, watchEffect } from 'vue'\nimport { projectFirestore } from '../firebase/config'\n\nconst getCollection = (collection, query) => {\n const documents = ref(null)\n const error = ref(null)\n\n let collectionRef = projectFirestore.collection(collection)\n .orderBy('createdAt')\n\n if (query) {\n collectionRef = collectionRef.where(...query)\n }\n\nconst unsub = collectionRef.onSnapshot(snap => {\n let results = []\n snap.docs.forEach(doc => {\n doc.data().createdAt && results.push({ ...doc.data(), id: doc.id })\n })\n documents.value = results\n error.value = null\n }, (err) => {\n console.log(err.message)\n document.value = null\n error.value = …Run Code Online (Sandbox Code Playgroud)