What is causing my vue.js table to not display properly?

Struggling to render a table using vue.js? You're not alone. Many developers face challenges when trying to use v-for to iterate through data and display it in a table format. It can be frustrating when everything seems fine in the console, but the table doesn't render as expected. So how can you tackle this issue effectively?

<template>
        <table class="table table-striped ">
          <thead>
            <tr>
              <th></th>
              <th>Name</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="user in users" :key="user.id">
                <td>{{ user.name }}</td>
                <td>{{ user.name }}</td>
            </tr>
          </tbody>
        </table>
</template>

<script>
    export default {
        props: [
            'users'
        ],
        data() {
          return {
            usr: [],
          }
        },
    }
</script>

Answer №1

If you have an array of user objects called `users`, you can loop through them using the following code:

<tr v-for="user in users" :key="user.name">
    <td>{{user.name}}</td>
    <td>{{user.name}}</td>
</tr>

This code snippet will iterate over each object in the `users` array, with `user` acting as the placeholder variable for each object.

<tr v-for="dumbledore in users" :key="dumbledore.name">
    <td>{{dumbledore.name}}</td>
    <td>{{dumbledore.name}}</td>
</tr>

Feel free to change `user` to any other name like `dumbledore` or any other alias you prefer.

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

Is there a way to obtain the component code prior to compiling in Vue2.x?

What is the purpose of this feature? <code-box title="基本" describe="button基本用法"> <i-button>Default</i-button> </code-box> I need to retrieve the default Slot String like <i-button>Default& ...

Tips for transferring information in JavaScript games

While browsing an HTML-based website, I am able to send POST and GET requests. However, in a JavaScript game like agar.io, how can similar actions be performed? Specifically, when playing a popular game like agar.io, how is my game state (such as positio ...

Unblocking the context menu: How entering JS directly into the address bar compares to using a bookmark

Exploring the concept of blocking the context menu using JavaScript. Here's how you can block such a menu: document.addEventListener('contextmenu', event => event.preventDefault()); I recently came across an article that mentioned this ...

Struggling to parse the JSON blob that was returned when using express-handlebars in node.js? Let

I am in the process of learning node.js and following a tutorial that involves making requests to the Accuweather API and receiving JSON data. Almost there ... but struggling with displaying the data: index.js const express = require('express' ...

Issue encountered: Vue js and d3 data visualization error - "d3 is not defined"

I am attempting to showcase a .json file as a treemap by using npm run dev. I thought I had everything set up correctly but it appears that an issue is arising. Below is my App.vue code: <template> <div id="app"> <title> { ...

What is the process for creating dynamic images using the npm run build command in vue.js?

Inside my src/assets/ directory, I have multiple images. In one of my components, I am using the following code: <img src="/src/assets/guna.jpg" alt="Guna" class="w-12 h-12 rounded-full" ...

Extracting the URL of the @font-face declaration in CSS with the use of JavaScript

Currently, my CSS file contains numerous @font-face tags. Each tag specifies a unique font-family and src URL. @font-face{ font-family: Garamond; src: url('ePrintFonts/pcl_91545.ttf'); } @font-face{ font-family: C ...

What is the best way to update the context while iterating through a jQuery each loop?

I am currently working on a code snippet that preprocesses response data retrieved from an AJAX call before displaying it (note: the display part is not included in this snippet). Specifically, it updates the src attribute of the image within each li eleme ...

How can we determine the total number of mandatory fields in an AngularJS form?

Can you explain how to calculate the number of required fields in a form using AngularJS? In my form, there are two required fields (email and select view). I want to display the count on my page - showing 2 if email is filled, 1 if only email is filled, a ...

How can I extract the return value of a JSON object and store it in a variable?

I am attempting to develop a dynamic chart by utilizing data retrieved from a function housed inside a JSON object. The JSON object is fetched through the Relayr Javascript API, and looks like this: relayr.devices().getDeviceData({ token: tok ...

Issue encountered while loading JSON data into DynamoDB's local instance

I have successfully set up DynamoDB local and everything is functioning as expected after going through their documentation. I have also tested their example code, which worked flawlessly. The Users table has been created with the name "Users". Below is ...

Using Vuejs to pass the SAVE function into a CRUD component

I am facing a challenge in finding a suitable solution that involves advanced parent-child communication in Vue.js. The scenario is such that there are multiple parent components, each with its own logic on how to save data. On the other hand, there is onl ...

Tips for generating a fixed-length array from multiple arrays with different lengths, focusing on selecting items from each array according to their significance

In order to create a quiz, I am looking to extract 'questions' from various 'topic' arrays. These topics are selected based on the user's preference and are used to populate a question bank for a 20-question quiz. The topics rated ...

Imagine a complex JSON structure with multiple levels of nesting

Take a look at this JSON data : { department_1 : [{ id : 1, name = Joe Smith, email : <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="660c150b0f120e2613150048030213">[email protected]</a>}, ...., { id : 500, name ...

Tips for Providing Real-Time Data for a Dynamic Chart in d3

I have a line chart sample from D3, and the issue I'm facing is that I need to continuously feed live data from a server at certain time intervals and use D3 to draw the chart based on this dynamic data. Despite my efforts to search for a solution, I ...

What rules should be followed in Python when it comes to using nested parentheses in functions?

Currently in the process of deleting my account from this platform, I am intentionally adding unnecessary content to this post. Please refrain from restoring the previous content. - Original Poster ...

Transforming JavaScript array UNIX timestamps into JavaScript Date objects

Is there a way to convert UNIX epoch integers into JavaScript Date objects using jQuery? Attempting to pass a large JSON array generated by PHP to Highmaps.JS, which works almost great. However, Highmaps expects a Date object and Date objects aren't ...

A Vue.js component containing a decimal variable within its data

When working with data in a Vue.js component, the decimal type is not included among the possible types (String, Number, Boolean, Array, Object, Date, Function, Symbol). How can we define a variable of this type? ...

How should you proceed when npm install cannot locate a specific dependency, even though you can easily download it manually?

Currently, I am faced with a dilemma while attempting to execute a JavaScript file that is accompanied by a package.json file. The issue arises during the npm install command in the folder as it fails to locate one of the dependencies. To address this pro ...

How to Invoke JavaScript Functions within jQuery Functions?

I'm working on a jQuery function that involves dynamically loading images and checking their width. I have two JavaScript functions, func1() and func2(), that I want to call from within the jQuery function in order to check the width of each image. T ...