Looping through an array of objects using V-for

Trying to iterate through an array of objects using v-for, but struggling with the syntax:

<ul>
    <li v-for="(data,index) in userStore.links">{{data.link}} - {{index}}</li>
</ul>

Issue: data.link displays nothing and index shows "link" which is confusing. But if I do this instead:

<ul>
    <li v-for="data in userStore.links">{{ data[0].link }}</li>
</ul>

Results: google.com <=== This works fine as long as I can increment 0 to 1.

Object Structure:

[ { "_id": "63f3db204ea92c071e2fe24c", "link": "hola.com", "shortLink": "7HG2zM6", "uid": "63e1314aa27f02c4b630c1a6" }, { "_id": "63f3dccb4ea92c071e2fe251", "link": "adios.com", "shortLink": "FsSuAwo", "uid": "63e1314aa27f02c4b630c1a6" }, { "_id": "63f3e1394ea92c071e2fe256", "link": "hola.gg", "shortLink": "0K8aRWz", "uid": "63e1314aa27f02c4b630c1a6" } ]

https://i.sstatic.net/zyYKI.png

https://i.sstatic.net/wAAES.png

Seeking advice on a different approach or how to increment the array index while iterating. Just need to display the entire object. Thank you.

Desired output for the whole array

Answer №1

When using Axios, it returns a proxy of the object. As you access this proxy, you may need to use an index. I found a solution by making them equal.

links = res.data ==> Now links=res.data.links 

This adjustment allows for seamless usage with v-for loop.

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

How can I extract the minimum price from this array list using Reactjs?

In my ReactJS project, I have an array list structured like this. I am trying to find the minimum price from this list. For example, if 'totalll' is 100, how can I achieve that? Please advise on how to navigate through the array to retrieve the i ...

Utilizing Selenium to add a JavaScript event listener will automatically activate it

After conducting thorough research, I've discovered that there is no direct way to capture user input using Selenium. In an attempt to work around this limitation, I have implemented a JavaScript event listener. Unfortunately, upon executing the code ...

Top method for establishing a mysql connection in Express version 4

Recently, I installed node-mysql and started running on express 4. Although I'm new to express, I am eager to learn the best practices for handling database connections. In my current setup, I have app.js var mysql = require('mysql'); //se ...

What is the best way to incorporate a Python variable into a JavaScript code?

I've been searching high and low for a method to interact with an invisible text field using Selenium's webdriver. I managed to make it work by utilizing driver.execute_script("document.getElementById('text_field').value+='XYZ&ap ...

Getting an unexpected empty response when submitting a request with a combination of image files and json parameters through postman, nodejs, and express

For my university project, I am developing a RESTful API for an online ticket shop that works across multiple platforms. I am using nodejs and express to create this API. First, I created the model for each event: const mongoose = require('mongoose&ap ...

What is the best way to ensure the submenu is visible on every menu when the cursor hovers over it

I am currently working on implementing a drop-down menu using react.js. I have been following a tutorial but encountered an issue when trying to add a submenu to the menu items. Instead of the submenu appearing only for the specific menu item hovered over, ...

Concealing the URL Once Links are Accessed

I have a Movie / TV Shows Streaming website and recently I've noticed visitors from other similar sites are coming to my site and copying my links. Is there a way to hide the links in the address bar to make it more difficult for them to access my con ...

Isotope animation glitches causing malfunction

I've been experimenting with CSS3 transitions on isotope items, but I'm encountering some strange behavior. My goal is to achieve a fading effect on the items, similar to this example: . Thank you in advance! Here's what I have so far: http ...

React.renderComponent does not exist as a valid function

After reading several articles on ReactJs for beginners, I came across a tutorial that only provided code snippets. While attempting to work on my first component, I encountered some difficulties: Here is the full code: <!DOCTYPE html> <html lan ...

The jquery click event is not working as expected

Hey there, I've been working on creating a dropdown menu that can be activated by clicking for better usability on touch screens. $('a.dropsmall2').click(function() { $(this).next('ul').slideToggle(500,'easeInOutQuad'); ...

Alter the Cascading Style Sheets (CSS) value by accessing a

I have two files, keyboard.css and keyboard.js. My objective is to modify a CSS rule: .ui-keyboard div { font-size: 1.1em; } Is there an alternative method to change the font size without utilizing $(".ui-keyboard div").css()? I want the modification ...

Gather all script tags and place them into an array

Here is a sample markup that I need help with: <p><span style="color: blue;">Yes this one now</span></p> <p><br></p> <p>The main configuration value is this</p> <p><br></p> & ...

Change res without altering the original argument

I'm developing an Express application and I've implemented the AirBnB eslint configuration for linting. The specific lint rule that caught my attention is no-params-reassign, which flags reassignment of function parameters as errors. While I appr ...

Struggling to employ JavaScript events when submitting a form to verify the fields

My goal is to create a form with fields that have real-time validation using JavaScript. I have achieved this by utilizing Java events in the following way: Text field onkeyup: This event sends a request to check for errors in the field every time a key ...

Navigating HTML with Node.js and Express.js

I have been working on routing multiple HTML pages in my project. The index.html file loads without any issues, but when I try to load raw.html, an error message pops up: Error: Failed to lookup view "error" in views directory Below is part of my app.j ...

Guide to adding information to an .xml document

Currently, I am working on building a website for a school project, specifically an online shop. I am focusing on the shop section, where I need to store data such as name, price, image, and description in either a text file or XML format. Right now, the w ...

Angular2 and ES6 Promise in JavaScript - tackling the issue of undefined variables

I am working with an array of objects like the one shown below: let PAGES = [ new BasePage( 'home', 'test') ]; let pagesPromise = Promise.resolve(PAGES); My goal is to retrieve a BasePage object by calling the following met ...

Freezing Columns and Rows for a Spacious Scrollable Table

After extensive effort, I have been diligently striving to create a solution that allows a table's column headers to scroll with the body horizontally and the first column to scroll with the rows vertically. While I've come across solutions that ...

Ensuring seamless functionality across all browsers for both hyperlinks and buttons

<input type="button" onclick="staff.updateDetail({$T.list.id},'staffno');" title="Change Details" value="{$T.list.staff_no}"> <a href="#" title="Change Details" style="color: #000" onclick="staff.updateDetail({$T.list.id},'staffno& ...

Is it possible to transmit an array using $.ajax and specify the dataType as json?

I am currently attempting to send a JavaScript array to my .php file handler and store it in my database. Although the request is successful, it seems like my array isn't being posted/saved correctly. When I check the POST request source, it shows up ...