Trouble displaying data table using Vue JS (v-for)

My goal is to display a table of data fetched from Firebase Firestore. I have successfully stored all the data in an array, but when I try to display it, the entire array appears instead of individual items. You can see the issue in the image below:

Here's the code snippet causing the problem:

<template>
  <v-simple-table>
    <template v-slot:default>
      <thead>
        <tr>
          <th class="text-left">
            Name
          </th>
          <th class="text-left">
            Calories
          </th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in result" v-bind:key="index">
          <td>{{ result }}</td>
        </tr>
      </tbody>
    </template>
  </v-simple-table>
</template>
<script>
import firebase from 'firebase' 
import {db} from '../service/firebase'
export default {
  data () {         
    return {
      userName: null,
      result: [],
      name: null,
      email: null,       
      userMail: null,
      telefone: null,
      userPhone: null,        
      userAccept: null,
    }
  },    
  async created() {    
    var userData = []
    await db.collection("users").get().then((querySnapshot) => {
      querySnapshot.forEach((doc) => {
        console.log(`${doc.id} => ${doc.data()}`);
        userData.push(doc.data())          
      });    
    });   
    this.result = userData.map(a => a.name)      
    console.log(result)          
  }    
}      

I'm looking for help on how to display single items from the array in the table, rather than the entire array at once. Any suggestions would be greatly appreciated. Thank you!

Answer №1

If you want to display the content correctly, make sure to use {{result}} like this:

<tr  v-for="(item, index) in result" v-bind:key="index" >
  <td v-for="(record,i) in item" :key="i">{{ record }}</td>
</tr>

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

Troubleshooting: Data retrieval issues in AngularFire within Ionic and Angular Application

I am encountering errors and facing issues with data retrieval in my Angular and Ionic application when using AngularFire for Firebase integration. Here is a snippet from my package.json file: "dependencies": { "@angular/common": "5.0.3", "@angul ...

No data is being recorded in the Firestore database

This component in nextjs is designed to write data to a firestore database after the user clicks a button. Unfortunately, Firebase seems to be having trouble writing the data, even though the alert message following the supposed data dump is successful. I ...

The method s.indexOf is not a valid function and throws an error at the `Function

I'm puzzled by this unexpected error popping up, as I can't pinpoint the source considering I haven't used that. Could it be related to my firebase update after a user modifies a row in DataGrid MUI? I followed the usual process for updating ...

What is the process for updating the data of a Single File Component using its own method?

Currently, I am diving into the world of Vue.js and exploring Single File Components. My goal here is to utilize the Geolocation API to prompt the user for their location, retrieve their latitude and longitude coordinates, and then display this information ...

Learn how to incorporate values on the Y axis using Vuetify examples

Recently, I've started using Vue.js and encountered some issues with a chart example from the official website. The example I'm currently working on involves a simple chart display. <template> <v-card class="mx-auto text-center" ...

Tips on incorporating a personalized components directory into your Gatsby project

I am looking to integrate some custom React components from a GitHub repository into my Gatsby project. However, I am unsure about how to include an external folder. The structure of the components folder that I want to incorporate is as follows: |-- /dis ...

Challenges in navigating routes with vue.js

Having some issues with my pages not displaying properly. I suspect it could be due to my routing setup. I am fairly new to this so any help would be appreciated. Here is a link to my project on GitHub: https://github.com/PietroSerra/order-login-master2 ...

Changing the global variable state within components in Vue 3: A step-by-step guide

I have recently started working with Vue3 and web development in general. My current setup involves using Vue3 with Express. I'm considering using a global property like app.config.globalProperties.$isAuthenticated and toggling it between true and fa ...

Adjustable Cursor - modify size while in motion at high speeds

I've designed a unique custom cursor and I am looking to enhance its functionality by adjusting its scale dynamically during fast movements. Similar to the cursor on this website: Example.com Here is my custom cursor for reference: CodeSandBox What ...

Is it possible in VueJS to access environment variables or configuration values in a static file during the build process?

Overview: I am currently working with VueJS, specifically utilizing the PWA template found at https://github.com/vuejs-templates/pwa. During the build process, there is a step called npm run build which bundles the project and transpiles any Vue code int ...

Webpack and Vue.js: Error - Definition missing for template or render function

I am encountering an issue while attempting to load a component in my root Vue instance. The error message I receive is displayed above. Below is the content of the main.js file: "use strict"; require('./../shared/bootstrap'); // loads jquery, ...

Retrieve information and functions from one component in a separate component

I currently have two components: ContainerSidebar.vue <!-- Sidebar --> <div id="b-sidebar"> <div class="change-image"> <img :src="profile.avatar != null ? profile.avatar+'#&apo ...

What is the best way to set an initial value retrieved from the useEffect hook into the textField input field?

I am working on an edit page where the initial values of first name, last name, and address are fetched from Firebase Firestore using useEffect. useEffect(() => { const unsubscribe = firestore .collection("users") .doc(uid) ...

Tips for accessing a composition function in VueJS from another composition

I've been diving into the new composition-api within VueJS and have encountered a problem that I need help with. I am seeking advice on how to effectively tackle this issue. Previously, when everything was vuex-based, dispatching an action to another ...

When the meta tag content "&" is used, it will be converted to "&amp;" in the final output

In my Nextjs webapp, I am utilizing Firebase to store images. The URI contains the "&" sign that is being converted to "&" inside the Head component. For instance, if I create a simple tag like this <meta property="test" content="& ...

`Can v-model be used to update the key of an object within an array element?`

My form is designed to fetch questions from an API, and I am looking to collect answers in separate input fields for each question. To achieve this, I have set up a response array with a length greater than or equal to the number of questions, pre-filling ...

Guide on adding checkboxes for each child component in a Vue ads table

<vue-ads-table :columns="fields" :rows="items" :selectable="true" @row-selected="onRowSelected" class="my-table" ...

How can I increase the index by 2 in a Vue.js v-for loop?

Below is an example of the code snippet: The code makes use of <ul> to loop through 7 times, where each iteration prints arr[0] and arr[1] inside the <li> tag. However, the requirement is to increment the index value by 2 for each subsequent ...

Looking to cycle through arrays containing objects using Vue

Within my array list, each group contains different objects. My goal is to iterate through each group and verify if any object in a list meets a specific condition. Although I attempted to achieve this, my current code falls short of iterating through eve ...

Adding data to an array using V-Bind in VueJS

I am currently working on a project that involves retrieving data from multiple devices and displaying the data on a chart in real-time. The goal is to update the chart every second as new data comes in. Below is the code snippet I have been using: index ...