Challenges encountered while trying to combine Vue 3 with Firestore

I am currently in the process of integrating Firebase (and Cloud Firestore) with my Vue 3 app. I have successfully installed the

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65030c170007041600255c4b554b57">[email protected]</a>
package into my project. Below are snippets of my code and console warnings.

Could someone please help me identify what I might be doing wrong?

firebase.js - contains my configuration and initialization settings

import { initializeApp } from 'firebase/app'
import { getFirestore } from 'firebase/firestore'

const firebaseApp = initializeApp({
  // Firebase app configuration
})

const db = getFirestore(firebaseApp)

export default db

BooksService.js

import db from '../firebase'
import { collection } from 'firebase/firestore'

const books = collection(db, 'books')

class BooksService {
  getAll () {
    return books
  }
  // other methods
}

export default new BooksService()

HelloWorld.vue - a sample component to display a list of books from Firestore

<template>
  <div>
    <h1>All books</h1>
    <ul>
      <li v-for="book in books" :key="book">
        {{ book }}
      </li>
    </ul>
  </div>
</template>

<script>
import BooksService from '../services/BooksService'

export default {
  data: () => ({
    books: []
  }),

  mounted () {
    this.books = BooksService.getAll()
  }
}
</script>

Here are the warnings and errors I encountered:

[Vue warn]: Unhandled error during execution of render function 
  at <HelloWorld msg="Welcome to Your Vue.js App" > 
  at <Home onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {…} > > 
  at <RouterView> 
  at <App>
[Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next 
  at <HelloWorld msg="Welcome to Your Vue.js App" > 
  at <Home onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy {…} > > 
  at <RouterView> 
  at <App>
Uncaught (in promise) TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'providers' -> object with constructor 'Object'
    |     property 'Map(8)' -> object with constructor 'Object'
    |     property 'platform-logger =>' -> object with constructor 'Object'
    --- property 'container' closes the circle
    at JSON.stringify (<anonymous>)
    at toDisplayString (shared.esm-bundler.js?9ff4:434)
    at eval (HelloWorld.vue?fdab:7)
    at renderList (runtime-core.esm-bundler.js?5c40:5747)
    at Proxy.render (HelloWorld.vue?fdab:3)
    at renderComponentRoot (runtime-core.esm-bundler.js?5c40:424)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js?5c40:4257)
    at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:160)
    at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:6656)
    at flushJobs (runtime-core.esm-bundler.js?5c40:6895)

Answer №1

const novels = collection(db, 'novels')

class NovelsService {
  retrieveAll () {
    return novels
  }
}

It appears that you are returning a CollectionReference instead of an array of documents, which is then assigned to this.novels in your component. Consider restructuring your code like this:

import { collection, getDocs } from "firebase/firestore"
const novels = collection(db, 'novels')

class NovelsService {
  retrieveAll () {
    return getDocs(novels).then(qSnap => {
        return qSnap.docs.map(d => ({id: d.id, ...d.data()}))
    })
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in TypeScript - Anticipated 1-2 arguments, received either none or multiple. Code Issue TS2556

While working in JavaScript, I had no issues with this code snippet. However, when I attempted to implement it in a TypeScript Project, an error surfaced. The problem seems to revolve around the fetch(...args) function call. const fetcher = (...args) =&g ...

In Vue.js, easily toggle classes with a click

I am having trouble figuring out how to apply a class to a button and then change it to another class after it is clicked. The idea is to have multiple buttons that serve as filters, allowing the user to select only one at a time with the selected button b ...

HTML5 input type Color displays individual RGB values

This code snippet opens up a variety of options for the user to manipulate different color values such as R, G, B, HEX VALUE, HUE, etc. However, the specific requirement is to only extract the Red value. <input id="color_pick"type="color" value="#ff0 ...

Switching between boolean values based on another value in react is a common practice

When a user is chosen from the list, a boolean value becomes true. If the chosen user is then unselected, the boolean turns false. This boolean will stay true if another user is selected from the list. Here's the code snippet: import React, { useEffec ...

Is it possible to simultaneously verify if an array is empty within an Object along with checking the other fields?

Let's say I have an object that has the following structure: filter: { masterName: '', service:[], } What is the best way to determine if both the array and masterName field are empty? ...

Utilize Jade to showcase information within an input field

I'm still learning Jade and am trying to showcase some data as the value in a text input. For example: input(type="text", name="date", value="THISRIGHTHURR") However, I specifically want the value to be set to viewpost.date. I have attempted various ...

What is the maximum storage capacity for variables on a NodeJS/ExpressJS server when handling multiple users?

As I delve into the node server code, I find myself pondering on the idea of storing temporary data - objects and arrays - within variables. These variables are housed in the client variable of a socket and are purged when connection with the client is l ...

Executing child processes in the Mean Stack environment involves utilizing the `child_process`

I am working on a Mean application that utilizes nodejs, angularjs and expressjs. In my setup, the server is called from the angular controller like this: Angular Controller.js $http.post('/sample', $scope.sample).then(function (response) ...

Determining if a component is nested within itself in Angular 6 is a crucial task

My goal is to develop a custom Angular component for a nested navigation menu with multiple levels. Below is an example of how the menu structure looks: app.component.html <nav-menu> <nav-menu-item>Section 1</nav-menu-item> <nav- ...

Tips on creating a hierarchical ul list from a one-dimensional array of objects

I have an array filled with various objects: const data = [ {id: "0"},{id: "1"},{id: "2"},{id: "00"},{id: "01"},{id: "02"},{id: "11"},{id: "20"},{id: "23"},{id: & ...

Having Trouble Importing My NPM Package Using ES6 Import/Export Syntax

I have been working on creating a new NPM package named notifman. Here are the steps I took: Started by creating the package.json: { "name": "notifman", "version": "1.0.5", "description": "Adva ...

What is the best method to incorporate a JavaScript object key's value into CSS styling?

I am currently working on a project in React where I'm iterating over an array of objects and displaying each object in its own card on the screen. Each object in the array has a unique hex color property, and my goal is to dynamically set the font co ...

Steps to combine multiple arrays into a unified array:1. Begin by allocating a

To form a league table, I have multiple individual arrays filled with data. In order to sort them by points, I want to merge these arrays into a single array called "teams". However, I am unsure if there is a function available to achieve this specific f ...

"pre and post" historical context

Is there a way to create a stunning "Before and After" effect using full-sized background images? It would be amazing if I could achieve this! I've been experimenting with different examples but can't seem to get the second 'reveal' di ...

Alerting JavaScript with element Selector doesn't function at full capacity

I am currently implementing Notify JS from the following source : Below is the HTML code I am using: <div> <p><span class="elem-demo">aaaa</span></p> <script> $(".elem-demo").notify( "Hello Box" ...

Retrieving the date from the final item in a JSON object using AngularJS

In my web application built with AngularJS, I am dynamically creating objects. The goal is to allow users to load new events by clicking a button. To achieve this functionality, I need to determine the date of the last event loaded so that I can fetch the ...

Streaming videos on Xbox One is not supported while in developer mode

Currently, I am facing a challenge with my UWP app that runs a web application made for Xbox One. There is a bug that only appears after approximately 4 hours of streaming video content, causing the app to freeze unexpectedly on the machine. The issue lie ...

When you reach the end of the page, the loadMore function is triggered multiple times

On my webpage, I have a list of profiles that are displayed. When the user reaches the bottom of the page, more data should be loaded through the loadMore function. While the loadMore function itself works correctly, I am facing an issue with the listener. ...

Can the fluctuations in resolution of webRTC streaming video be detected?

We are currently working on a project involving WebRTC and have specific requirements that involve detecting when the resolution of the streaming video (remote stream) changes in WebRTC. Is there a way for us to achieve this? Any tips or guidance would be ...

Is it possible to use various v-for loops to showcase different cities within countries?

I'm currently working with vue.js and axios in visualstudiocode. As a beginner in coding, I apologize if my question is not articulated well. Utilizing data from the following API: '' One array consists of countries and their corresponding ...