typeError object(...) 不是一个函数

typeError object(...) is not a function

我在出现“setup()”函数的那一行收到“对象不是函数”错误。 我不知道如何调试这个......我做错了什么吗? (我不是一个经验丰富的开发人员,所以我知道我做错了,但在这里,我不知道它是什么......)

它要求我添加更多细节,因为我的 post 主要是代码...所以我正在写这篇文章,但我想知道我可以添加哪些细节。 :-)

在此先感谢您的帮助!!

<script>
  import { ref } from 'vue' 
  import Ftable from '@/components/tables/Ftable.vue'
  import Searchbar from '@/components/tables/Searchbar.vue'
  import getMainCollection from '@/composables/getMainCollection'
  
export default {
    name: 'Home',
    components: { Searchbar, Ftable },
    
    setup(){    //error arrives on this line

      const { getData, getMore } = getMainCollection()
      const documents = ref('')
      const lastVisible = ref('')
      const type = ref('')
      const country = ref('')

      function newSearch() {
        const {doc, last} = getData(type, country)
        documents.value = doc
        lastVisible.Value = last
      }

      function askForMore() {
        const { doc, last } = getMore(type, country, lastVisible)
        documents.value = doc
        lastVisible.value = last
      }
      
      

        return { documents, askForMore, newSearch, askForMore }

    }

}
</script>

import { ref } from 'vue'
import { projectFirestore } from '@/firebase/config'

const getMainCollection = () => {

const collectionGroupRef = projectFirestore.collectionGroup('users')
const lastVisible = ref('')
const documents = ('')

function getData(type, country) {
    const filter = null
    if (type != null && country == null){
        filter = collectionGroupRef.where('type', '==', `${type}`)
    }
    else if(type == null && country != null){
        filter = collectionGroupRef.where('country', '==', `${country}`)
    }
    else{
        filter = collectionGroupRef
    }

    const data = filter.orderBy('createdAt')
    .limit(2)
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            documents.value.push({ ...doc.data(), id: doc.id})
        })

    lastVisible = querySnapshot.docs[querySnapshot.docs.length-1]

    })
    return( documents, lastVisible)
}

function getMore(type, country, lastVisible) {
    const filter = null
    if (type != null && country == null){
        filter = collectionGroupRef.where('type', '==', `${type}`)
    }
    else if(type == null && country != null){
        filter = collectionGroupRef.where('country', '==', `${country}`)
    }
    else{
        filter = collectionGroupRef
    }
    filter.startAfter(lastVisible)
    .limit(2)
    .orderBy(createdAt)
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            documents.value.push({ ...doc.data(), id: doc.id })
        })
    lastVisible = querySnapshot.docs[querySnapshot.docs.length-1]
    })
    return( documents, lastVisible)
}

return ( getData, getMore )
}

export { getMainCollection }

自从您将 getMainCollection 导出为对象后:

export { getMainConnection }

导入时需要解构:

import { getMainCollection } from '@/composables/getMainCollection'