I'm currently working on optimizing my code for reusability, and I've decided to store multiple async functions in a separate file.
blog.ts
import db from '@/firebase/init'
async function fetchTags (uid) {
const tags = db.collection('tags').where('blogId', '==', uid)
const data = []
await tags.get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.data())
data.push(doc.data().tag)
})
return data
})
.catch(error => {
console.log('Error fetching documents', error)
})
}
export default fetchTags
anotherpage.vue
<script>
import { fetchTags } from '@/functions/blog'
mounted () {
if (this.$route.params.blog) {
this.blog = this.$route.params.blog
}
fetchTags(this.blog.uid)
}
An error message is returned stating that:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in mounted hook: "TypeError: Object(...) is not a function"
found in
---> <EditBlog> at src/components/admin/admin/Blog/EditBlog.vue
<CreateBlog> at src/components/admin/admin/Blog/CreateBlog.vue
<LayoutDefault> at src/App.vue
<Root>
If anyone knows of a guide that explains the correct way to import these functions, please share it with me.