Using V-For with data fetched from an axios request: A step-by-step guide

How can I dynamically populate V-Cards after making an Axios request to retrieve data?

The Axios request is successful, but the v-for loop does not populate with V-Cards. I've also attempted to make the request before the rendering is completed (using the beforeCreate lifecycle event), but that approach also fails.

Edit: The data retrieval is successful, leading me to believe there may be an issue with how the v-for loop is functioning? Could I be overlooking something? View response data here

<template>
  <v-container class="pa-2" fluid>
      <v-layout v-for="(clip) in clipData" :key="clip.id">
        <v-card>
          <v-img
            :src="clip.thumbnail_url"
            class="white--text"
            height="200px"
          >
            <v-card-title class="fill-height align-end" v-text="clip.title"></v-card-title>
          </v-img>
        </v-card>
      </v-layout>
  </v-container>
</template>

<script lang="ts">
// Imports omitted for brevity


@Component({
  components: {}
})
export default class Clips extends Vue {

  public clipData: any;

  mounted() {
    // Axios Request Data From twitch helix API regarding Clip Information on My channel
    helix.get('clips?broadcaster_id=<myidOmitted>&first=10').then((data) => {
        this.clipData = data.data.data; // <-- Third data is the array of clips i need.
    }).catch((err) => {
        console.log(err)
    })
  }
}
</script>

Answer №1

To optimize your code for using "ts", you can make the mounted hook async and use await for axios call like this:

async mounted() {  

  let result = await helix.get('clips?broadcaster_id=<myidOmitted>&first=10');
  if(result.data){
    this.clipData = result.data.data;
   }  
 }

Give it a try and see if this approach works better for you.

Answer №2

After exhausting all other options, I began to ponder the possibility that the UI was not updating after the data retrieval process.

So, within my Parent Container, I introduced a Property with v-if:

<v-container class="ma-10" v-if="!isFetching" >

Upon completion of the Axios call, I then set this property to false:

helix.get('clips?broadcaster_id=<idOmitted>&first=8').then((data) => {
    this.clipData = data.data.data; // <-- Third data is the array of clips i need.
    this.isFetching = false;

This simple solution immediately resolved the issue. It seems that setting a variable triggered a re-render of the UI. I am uncertain why this worked when we were already setting a variable (clipData).

Nevertheless, problem solved for now!

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

Tips for streamlining interface initialization and adding items to it

I have designed an interface that includes another interface: export interface Parent { children: Child[]; } export interface Child { identifier: string; data: string; } Is there a more efficient way to initialize and add items to the array? Curren ...

Redirecting the socket.io client to the Heroku service

Recently, I developed a real-time chat application using socket.io, Node.JS, and express. It was functional on my local server but now I want to connect it to an existing Heroku service instead. How can I achieve this? Once I tried the following code, va ...

How to use expressjs to fetch an image from a URL and show it on a webpage

I am currently running an image API from my home server, and I am working on creating a cloud-hosted page that will retrieve the image in the backend and display it, adding a layer of abstraction. My goal is to achieve the following: index.js var express ...

Challenges when it comes to exporting files using Firebase Cloud Functions

I've been working with Firebase Cloud Functions using JavaScript, but I'm encountering issues with the import and export statements. Is there a solution to replace them? const firebase = require('firebase'); const config = { apiKe ...

Utilizing Laravel's Eloquent to retrieve interrelated data from tables through foreign keys

I am looking to retrieve fields from a controller using Eloquent with the data of another class through foreign keys. I am unsure if this is possible or not. The situation Model Job class Job extends Model { use HasFactory; /** * The attr ...

Limit the option to check or uncheck all on the current page only

I am facing an issue with a select all checkbox that interacts with checkboxes in a paginated table. The problem arises when I check the select all box, as it selects all records instead of just those on the current page. For example, if there are 200 reco ...

Printing reports in Angular 9

I have a requirement in my Angular 9 application to generate and print reports. 1. I am looking for suggestions on how to handle printing reports where a user triggers the action by clicking a button, and the report data needs to be fetched from the datab ...

What steps are necessary to configure karma webdriver launcher to utilize my selenium server or grid?

Could someone assist in identifying what is causing the Karma javascript test runner to have issues connecting to and utilizing my selenium grid/server? I currently have a functioning selenium grid setup that I utilize with python selenium bindings for co ...

Preserve final variable state - Angular

My function looks like this: flag: boolean = false; some_function(){ var foo = some_num_value; var bar = foo; // Storing value in a separate variable if(this.flag){ v ...

Executing a Drupal rule using JavaScript: A step-by-step guide

I'm facing a challenge when trying to activate a Drupal rule using JavaScript code. lowerLayer[image.feature_nid].on("dragend", function() { var position = kineticImage.getPosition(); var layerPosition = this.getPo ...

What is the method to obtain the current data source filter for a Kendo UI grid in a Vue application?

Looking to retrieve the current datasource filter using Kendo UI for jQuery? Simply use dataSource.filter() However, when it comes to the Vue.js version, finding the equivalent seems challenging. I've prepared a demo here. The current filter is appli ...

Can the return type of a function be utilized as one of its argument types?

When attempting the following code: function chain<A, B extends (input: A, loop: (input: A) => C) => any, C extends ReturnType<B>> (input: A, handler: B): C { const loop = (input: A): C => handler(input, loop); return loop(input) ...

What are some solutions for resolving a TypeError in the created hook of a Vue.js application

Oops, there seems to be an error: vue.js:597 [Vue warn]: Error in created hook: "TypeError: handlers[i].call is not a function" found in ---> <StageExecs> vue.js <div id="vue-job"> <div class="row"> <h3>test</ ...

Why is the Mongoose ObjectID causing issues when used as a parameter in a function?

Attempted passing a Mongoose ObjectID to a function using an onclick(). Below is the shortened code snippet: <a onclick="Like({{_id}}, {{likes}}, {{dislikes}});" class="btn btn-like"></a> <p id="{{_id}}"> {{likes}} likes </p> < ...

Creating a Select component in React without relying on the Material-UI library involves customizing a dropdown

Is there a way to achieve a material UI style Select component without using the material UI library in my project? I'm interested in moving the label to the top left corner when the Select is focused. export default function App({...props}) { retu ...

Layout display issue post redirection in React

I am facing an issue with my app that utilizes styled-components and material-ui. I have set up private routes based on user roles, and when a non-authenticated user is redirected to the login page, the layout fails to load properly. App.tsx import React ...

Utilizing Sails.js: Invoking a YouTube service through a controller

I am facing an issue while trying to integrate Youtube Data API with Node.js in Sails.js. The problem lies with the "fs.readFile" function. Upon launching the service, it returns "undefined". Below is the code snippet for YoutubeService : module.exports ...

Combine arrays and group them together to calculate the total count of each unique value in the merged array

I have a dataset similar to the following: { "_id" : ObjectId("5a4c6fb6993a721b3479a27e"), "score" : 8.3, "page" : "@message", "lastmodified" : ISODate("2018-01-03T06:49:19.232Z"), "createdate" : ISODate("2018-0 ...

"Encountering an undefined error when making an AngularJS $http post request and receiving a

I am working on retrieving a specific value from the server side by passing a variable from the front-end (AngularJS javascript) to the backend (PHP) using $http. Once the server side (PHP) receives the value from the front-end, it executes an SQL query to ...

JSON Array Position Sequence

I have a system that takes input in the form of lines of text stored as an array, for example: array[123,556,"test",0,0]. By using val().split('\n'), I am able to add each new line to the array so that each line index is incremented by 1. He ...