Challenges with managing VueJS methods and understanding the component lifecycle

I'm facing an issue with my code. The function retrieveTutorials() is not transferring the information to baseDeDatosVias as expected. I've attempted to change the function to a different lifecycle, but it hasn't resolved the problem. The solution might be simple, but I haven't been able to pinpoint it yet. Thank you in advance for your assistance!

methods: {
  retrieveTutorials() {
    TutorialDataService.get(this.$auth.user.name)
      .then(response => {
        this.baseDeDatosVias = response.data;
        console.log(this.baseDeDatosVias);
      })
    .catch(e => {
      console.log(e);
    });
  },


  populateGrados() {
  this.retrieveTutorials();
  this.cantViasEncadadenasPorGrados= [];
  const keys = Object.keys(this.baseDeDatosVias);
  console.log(keys);

(I am aware that I also need to correct all the "else ifs")

Here is the full code snippet:

<template>
  <div>
    <!--Stats cards-->
      <div class="row">
        <div class="col-lg-3 col-md-6 col-sm-6" v-for="stats in statsCards">
          <stats-card :type="stats.type"
                    :icon="stats.icon"
                    :small-title="stats.title"
                    :title="stats.value">
            <div class="stats" slot="footer">
              <i :class="stats.footerIcon"></i>
              {{stats.footerText}}
            </div>
          </stats-card>
        </div>
      </div>  
    <div class="row">
      <div class="col-md-6">
      <card>
        <template slot="header">
          <h4 class="card-title">Vias encadenadas por grado</h4>
          <p class="category">Por cantidad</p>
        </template>
        
        <bar-chart :labels="cantidadDeEncadenadas.labels"
                   :height="250"
                   :datasets="cantidadDeEncadenadas.datasets">
        </bar-chart>
        </card>
      </div>
    <div class="col-md-6">
      <card>
        <template slot="header">
          <h4 class="card-title">Progresion en el tiempo</h4>
          <p class="category">Proximamente</p>
        </template>
        <line-chart :labels="stockChart.labels"
                    :height="250"
                    :color="stockChart.color"
                    :extra-options="stockChart.options"
                    :datasets="stockChart.datasets">
        </line-chart>
      </card>
    </div>
      </div>

    <div class="row">
      <div class="col-lg-3 col-sm-6">
        <circle-chart-card :percentage="70"
                           chart-id="email-statistics-chart"
                           title="% de Vias Encadenadas"
                           description="Sobre el total de Realizadas"
                           color="#4acccd">
          <template slot="footer">
            <div class="legend">
              <i class="fa fa-circle text-info"></i> Encadenes
            </div>
            <hr>
          
          </template>
        </circle-chart-card>
      </div>

      <div class="col-lg-3 col-sm-6">
        <circle-chart-card :percentage="34"
                           chart-id="new-visitors-chart"
                           title="% de Vias a Vista"
                           description="Sobre el total de Encadenadas"
                           color="#fcc468">
          <template slot="footer">
            <div class="legend">
              <i class="fa fa-circle text-warning"></i> A Vista
            </div>
            <hr> 
          </template>
        </circle-chart-card>
      </div>  
    </div>

  </div>
</template>
<script>
  import LineChart from 'src/components/UIComponents/Charts/LineChart'
  import CircleChartCard from 'src/components/UIComponents/Cards/CircleChartCard.vue'
  import ChartCard from 'src/components/UIComponents/Cards/ChartCard';
  import StatsCard from 'src/components/UIComponents/Cards/StatsCard';
  import {Badge} from 'src/components/UIComponents'
  import Loading from 'src/components/Dashboard/Layout/LoadingMainPanel.vue'
  import TaskList from './Widgets/TaskList'
  import BarChart from 'src/components/UIComponents/Charts/BarChart'
  import { Card } from 'src/components/UIComponents'
  import users from 'src/components/Dashboard/Views/Tables/users.js'
  import TutorialDataService from "src/services/TutorialDataService.js";

  // Additional code removed for brevity

export default {

// Component details and methods
}

</script>
<style>

</style>

Answer №1

It seems like the problem might be related to an async issue, so you can try the following solution:

async populateGrades() {
    await this.fetchTutorials();
    // add the rest of your code here
}

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

What has become of the main template or layout file in this SSR Vue server-side rendering webpack example?

The documentation for ssr vue (server side rendering for vuejs) includes an example of code structure that involves a webpack build step: Here is how the structure appears: src ├── components │ ├── Foo.vue │ ├── Bar.vue │ ...

Is there a way to execute a jar file using JavaScript?

Hello, I'm new to this and still learning. I have a jar file that takes one parameter and returns a JSON with the result. Could someone please advise me on how to run my jar using JavaScript? I've attempted the following code but it's not wo ...

Why do Vue/Nuxt Select field states come pre-set as valid?

My Nuxt.js form contains multiple HTML select elements, each with validation using Vuelidate. The validation is working correctly. Here is an example of one of the select boxes in my form: <select id="location" name="location" v-m ...

Is there a more efficient method for invoking `emit` in Vue's Composition API from an external file?

Is there a more efficient way to access the emit function in a separate logic file? This is my current approach that is functioning well: foo.js export default (emit) => { const foo = () => { emit('bar') }; return { foo }; } When ...

Avoid These Mistakes When Combining Link URLs in VueJS

I'm embarking on a new project and I'm faced with an issue regarding rendering a list of links. The URLs of my links are stored in a table in the format of "www.sitename.com". They display correctly initially, but upon clicking on one of them, in ...

How can I dictate the placement of a nested Material UI select within a popper in the DOM?

Having trouble placing a select menu in a Popper. The issue is that the nested select menu wants to mount the popup as a sibling on the body rather than a child of the popper, causing the clickaway event to fire unexpectedly. Here's the code snippet f ...

How to toggle the display of a div by its id using index in Javascript

Currently, I am encountering a problem with toggling the div containers. When I click on the video button, I want the other divs to close if they are already open. However, due to the toggling mechanism, if a div is closed and I click on the corresponding ...

How to Create a Speech Bubble in SVG Using SnapSVG

In the process of developing a chat program, I have animated figures moving across the screen engaging in conversations. One crucial aspect I am yet to implement is creating scalable speech bubbles for when users interact. Being relatively new to SVG and ...

The medium-zoom feature is currently experiencing issues with functionality within Angular version 13

I've been attempting to incorporate medium-zoom functionality into my project using https://www.npmjs.com/package/medium-zoom Here are the steps I took: ng new medium_zoom_test (Angular 13) with routing & css npm install medium-zoom The image is ...

When using JSON stringify, double quotes are automatically added around any float type data

When passing a float data from my controller to a JavaScript function using JSON, I encountered an issue with quotes appearing around the figure in the output. Here is the JS function: function fetchbal(){ $.ajax({ url: "/count/ew", dataType: "jso ...

Struggling to get Ajax to function on IE8 with dropdowns, while other browsers are working perfectly fine

My AJAX code functions properly in most browsers, however, it is not performing well in IE. While it successfully creates an XMLHTTPRequest object, the data retrieved from my PHP script is only returning an empty list! Check out my JavaScript code: < ...

Tips on transforming truncated surfaces into complete entities

When working in Three.js, I encountered a situation with a 3D object where local clipping planes were used to render only a specific part of the object. However, due to the nature of 3D objects being "hollow" (only rendering the outer surface), when somet ...

The html function does not contain the value of the textarea

While attempting to retrieve the HTML content of a div using the code below, I noticed that it does not include the text entered in the textarea or input field. var mywindow = $(printDiv).html(); The variable mywindow will contain all the HTML except fo ...

Instructions for modifying the color of the close button in the angularjs ui-select module

I am currently using ui-select for multiple selection in a dropdown. When an item is selected, it displays a cross button on the upper right corner of the selected item. Is there a way to change the color of the cross button to red? <ui-select multip ...

How can I delay the loading of a link until the pop-up is closed?

I have successfully implemented a pop-up on my website, but I am facing an issue where I need to prevent any linked pages from loading until the visitor clicks on the accept button. However, I am struggling to make it function as intended. Below is the sn ...

I'm having trouble with res.redirect, why isn't it redirecting me as expected?

In my login controller, I have a form that updates the user's scope when they click a button triggering the login() function. .controller('loginCtrl', ['$scope','$http',function($scope,$http) { $scope.user = { ...

What is the best way to shift a list to the right within my navigation bar using ReactJS and CSS?

I'm looking to align a list to the right in my navbar, as shown in the image below Image Here's my navbar.js code: import React from "react"; import "./Navbar.css"; const Navbar = ({ isScrolling, information }) => { ...

Making adjustments to regular expressions

In my asp.net application, I have a text box where users input a URL and I am using a regular expression for validation. The current regular expression looks like this: ^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(&bsol ...

What could be the reason for Vue not finishing the build process?

Screenshot of Files Second Screenshot of Files Upon creating a new project using Vue3 and Vite (v4.3.1), I encountered an issue where the npm run build command failed to compile my project correctly. While the build command appeared to be successful, wit ...

Using JQuery AJAX to successfully retrieve data and then smoothly applying the fadeIn

Utilizing AJAX, I am loading survey content into a container on a webpage. As part of the transition, I have implemented a fadeOut effect on the container, followed by fadeIn once the content is loaded. This method functions correctly for pages 1-4; howeve ...