【发布时间】: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