小编Cph*_*444的帖子

(Vue) 我在重用可组合函数的引用时遇到问题

我希望我可以包含完整的代码。不然很难理解我的问题。

\n

我为我的 Vue 应用程序创建了一个可组合函数,其目的是从数据库中获取文档集合。\n可组合函数如下所示:

\n
import { 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)

vue.js vuejs3 vue-composition-api

1
推荐指数
1
解决办法
849
查看次数

标签 统计

vue-composition-api ×1

vue.js ×1

vuejs3 ×1