【问题标题】:typeError object(...) is not a functiontypeError object(...) 不是函数
【发布时间】:2021-04-18 07:14:21
【问题描述】:

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

它要求我添加更多细节,因为我的帖子主要是代码......所以我正在写这个,但我知道我可以 c=可能添加哪些细节。 :-)

提前感谢您的帮助!!

<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 }

【问题讨论】:

  • 你能分享@/composables/getMainCollection'文件吗?也许import { getMainCollection } from '@/composables/getMainCollection'
  • 你去...我添加了文件
  • 你可以这样做export default getMainCollection并且不需要更改导入

标签: vue.js vue-composition-api


【解决方案1】:

由于您将getMainCollection 导出为对象:

export { getMainConnection }

导入时需要解构:

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

【讨论】:

  • 哈哈!!谢谢!我在徘徊为什么有时花括号在那里,有时却没有。我正在学习在线课程,但我自己构建了这部分......
猜你喜欢
  • 2019-08-12
  • 2018-10-25
  • 2021-01-25
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 2021-09-28
  • 2021-12-22
  • 2019-07-05
相关资源
最近更新 更多