How come Vue.js and Axios aren't displaying the data I specified?

When I utilize Vue.js + Axios to query data from a third party API, the response is returned with a slightly confusing nested array structure. However, upon rendering the data at the frontend, I encounter an issue where no information is displayed.

It's worth noting:

After running the code, Vue adds exactly 20 html divs on the frontend, matching the number of elements, but fails to display the corresponding data (refer to images below).

What could potentially be causing this problem?

Javascript snippet:

var app = new Vue({
    el: '#app_name',
    data: {
      info: []
    },
    mounted() {
      axios
        .get("https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/leagueTable/" + league_id)
        .then(response => {
          this.info = response.data.api.standings[0];
          console.log(response.data.api.standings[0]);
        });
    }

HTML segment:

          <div class="table" id="app_name">
            <div><p>Team</p></div>
            <div v-for="Rank in info">

            <p>{{ Rank }}</p>

            </div>

JSON return showing the nested array:

{
    "api": {
        "results": 1,
        "standings": [
            [
                {
                    "rank": 1,
                    "team_id": 85,
                    "teamName": "Paris Saint Germain",
                    ...
                },
                {...}
            ]
        ]
    }
}

Before executing Javascript:

https://i.sstatic.net/o9hf2.jpg

After running Javascript:

https://i.sstatic.net/S5qH4.jpg

UPDATE

Even after trying out the modification mentioned here, I still face difficulties in rendering any data.

  var app = new Vue({
    el: '#app_name',
    data: {
      info: []
    },
    mounted() {
      axios.interceptors.request.use(config => {
        config.paramsSerializer = params => {
          // Qs is already included in the Axios package
          return Qs.stringify(params, {
            arrayFormat: "brackets",
            encode: false
          });
        };
        return config;
      });
      axios
        .get("https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/leagueTable/" + league_id)
        .then(response => {
          this.info = response.data.api.standings;
          console.log(response.data.api.standings);
        });
    }

Answer №1

 <div v-for="Level in statistics">

 <p>{{ Level }}</p>

In this context, Level represents an element included in the object. If you want to refer to a specific key within that object, you should use:

<p>{{ Level.level }}</p>

Answer №2

https://i.sstatic.net/Rhvq5.png
The output from your API appears to be empty, possibly due to using a demo version.
As a result, Vue is unable to display any items on the page. This issue may stem from server complications rather than errors in your code.
Consider exploring alternative APIs if the problem persists.

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

Issue: Unspecified error when trying to access object attribute in Vue (Nuxt)

I am facing an issue with my 'region' object. It appears to be displayed correctly with all its attributes, but when I try to access specific attributes, it shows up as 'undefined'. const region = { "id": 7, "name": ...

Saving asp.net strings in different formats to datetime fields in a database

Can someone please assist me with saving the string value of textbox to the database as a datetime, and for updating/editing purposes, display it again in the textbox as a string? The reason for this is that the datetime input will be copied from Outlook a ...

Steps for showing an error prompt when input is invalid:

In my Vue 3 application, I have implemented a simple calculator that divides a dividend by a divisor and displays the quotient and remainder. Users can adjust any of the four numbers to perform different calculations. <div id="app"> <inp ...

Overlaying images on top of text

Is there a way to overlay an image on text, like a pattern image? Similar to applying color with a hex value in CSS: color: #ffffff; Any ideas on how this can be achieved? I want to have a pattern over text. https://i.sstatic.net/JaNZU.jpg Appreciate ...

Stop jQuery Tab from Initiating Transition Effect on Current Tab

Currently, I am utilizing jQuery tabs that have a slide effect whenever you click on them. My query is: How can one prevent the slide effect from occurring on the active tab if it is clicked again? Below is the snippet of my jQUery code: $(document).read ...

What is the method for retrieving properties with varied names from a collection?

My collection has the following structure https://i.sstatic.net/FZIqt.png Is there a way to access properties with different names within a collection? I attempted it this way: for(i=0;i<$scope.users.length;i++) { console.log($scope.users[i].goo ...

Increase the value of (N) in the copied MongoDB file name

Are there any algorithms available to handle incrementing numbers in duplicate filenames? For instance, let's consider a simple collection of documents stored in a file collection: [ { "_id": "612ead8668bfcc4221a788f6" ...

Encountering an error trying to access 'version' in vue-bootstrap due to undefined properties

I recently downloaded npm packages based on the requirements outlined on . Here is how my package.json file looks: "dependencies": { "bootstrap": "^4.0.0", "bootstrap-vue": "^2.23.1", }, My main. ...

As I enlarge the font size, the border around the div also expands

Can someone explain why the size of the div border increases along with the font size? If you'd like to see an example, check out this link to a jsFiddle: LINK TO JS FIDDLE: http://jsfiddle.net/krishna22211/m14qms52 ...

Activating Durandal's knockout click functionality

I am struggling and need some assistance. I have tried various solutions, but I can't seem to get the click event working when I try to delete a free day by clicking on the icon. The other click events are functioning correctly. Here is my code snippe ...

Generate a 2D matrix to represent a grid

I have a list of numbers that I need to convert into a two-dimensional array. For example: let data=['1','4','2','1','6','9','1','5',] The desired output would be: result = ...

Using Lodash to Substitute a Value in an Array of Objects

Looking to update the values in an array of objects, specifically the created_at field with months like 'jan', 'Feb', etc.? One way is to loop through using map as demonstrated below. However, I'm curious if there's a more co ...

Vue.js has a feature where it automatically closes the form tag within a for loop

In my Vue.js application, I have created a table where each row is a form with a submit button. This is the code snippet I am using: <div id="admin-user"> <table class="table"> <tr v-for="(user, index) in users"> < ...

Having trouble updating a text field on an event using JavaScript - value not defined

When I change the select option, my goal is to dynamically set the value of the input using JavaScript. However, I am encountering an issue where the value becomes undefined. Below is a snippet from my HTML (JSP) file: <body> <center>< ...

Is there a way to implement this code to filter every column in the grid?

I have been using this code in my grid view, but it only filters one column of the grid. Now I want to modify the code to filter multiple columns. I tried implementing a loop, but it seems like the code is not working correctly. Is there a way to adjust t ...

Loading will continue until the webpage has finished loading

I want to incorporate a loading animation into my webpage that will be displayed until all elements have finished loading. I attempted to create a popup alert using JavaScript <script type="text/javascript> window.onload = function() { a ...

A guide on iterating through a collection of elements in VueJS

I may have approached this project completely wrong from the start, so any advice is greatly appreciated. My goal is to design a simple webpage with input fields on the right and corresponding hints on the left. When an input field is focused on, the rele ...

Utilizing Bootstrap 4 icons in Laravel along with VueJS: A comprehensive guide

After successfully installing Bootstrap icons into my Laravel/VueJS application using NPM following the guidelines provided at , I am unsure of what the next step should be. If I wish to utilize the svg element in a blade template, is it necessary to comp ...

Angular 12: Running ng test shows code coverage error - TypeError: Unable to access 'initialize' property as undefined

I encountered an error in the code coverage console: TypeError: Cannot read properties of undefined (reading 'initialize') I am trying to call a service method from the component.ts file The code in the component.ts file looks like: this.myAuth ...

Disabling font-awesome checkboxes

As someone who is new to front-end technologies, I am trying to achieve the following. Despite my efforts to find a solution, I have not been successful so far. Here is the issue I am facing-- I have two master checkboxes labeled 1) I do not like numbers ...