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

the order of initialization in angularjs directives with templateUrl

In my current scenario, I am faced with a situation where I need to broadcast an event from one controller and have another directive's controller receive the message. The problem arises because the event is sent immediately upon startup of the contro ...

Using Reactjs to create a custom content scroller in jQuery with a Reactjs twist

I am attempting to implement the Jquery custom scrollbar plugin here in my React project. Below is a snippet of my code: import $ from "jquery"; import mCustomScrollbar from 'malihu-custom-scrollbar-plugin'; ..... componentDidMount: function() ...

Displaying data on View is not working after navigation

I'm facing an issue where the data is not displaying on the view after routing, even though it appears in the console. Surprisingly, if I don't change the view, the data shows up. Additionally, if I call the service directly from the view, I can ...

Sending emails with SMTP in JavaScript using the mailto form

I'm facing a challenge with my form. I am looking for a way to have the Send-email button trigger mailto without opening an email client, instead automatically sending via JavaScript (smtp). I'm not sure if this is achievable or if I'm askin ...

Guide for displaying and hiding an image using a button or link in Next.js

I'm a beginner with React and Next.js, and I have the following code snippet: import Link from 'next/link'; import Image from 'next/image'; async function getPokedex() { const response = await fetch(`http://localhost:3000/api/p ...

Avoid Scrolling within an iFrame in HTML with the Use of #

I have a menu loading in an iframe with links using # like http://<location>/page.html#part1. When I click inside the iframe, the entire page outside of the iframe scrolls to the location of #. How can I stop this from happening? I only want the me ...

Can someone please explain the distinction between $http.get() and axios.get() when used in vue.js?

I'm feeling a little bit puzzled trying to differentiate between $http.get() and axios.get(). I've searched through various sources but haven't found any answers that fully satisfy me. Can someone please offer some assistance? ...

Guide on accessing APIs for individual elements in an array

Currently utilizing Next.js / React.js and making use of this API to retrieve information about a specific country. Within the response, there exists an array called borders, as shown below: borders: [ "CAN", "MEX", ], There is ...

AngularJs tip: Harness the power of parallel and sequential function calls that have interdependencies

service (function () { 'use strict'; angular .module('app.user') .factory('myService', Service); Service.$inject = ['$http', 'API_ENDPOINT', '$q']; /* @ngInject ...

Guide to updating a database using ajax and javascript in asp.net mvc without the need to refresh the page

Is there a way to update the value of an enumdropdownlist from "active" to "inactive" in my database through an ajax call without having to refresh the page? I am unsure whether to use a javascript method or ajax.beginform for this task. I attempted to us ...

The reactivity of external objects with the data options property in Vue.js 3 has been disabled

My app shares an external module with other applications by utilizing a global Javascript object. One of these apps is created using vue 2, and whenever the global object is updated in the external module, the option data property of vue 2 updates perfect ...

A guide to spinning an image in every direction with CSS

I'm working on rotating an image in all directions using CSS and Vue.js. To demonstrate this, I have created a CodePen with the necessary code below. <div id="app"> <v-app id="inspire"> <div class="text-xs-center image-rotation" ...

React Context - Ensure synchronized deletion of user posts across routes while maintaining pagination during fetching

INTRODUCTION I am striving to replicate the behavior commonly seen in social networks, where deleting a post by a user results in its automatic removal across all app routes. This functionality is reminiscent of how platforms like Instagram or TikTok oper ...

Learning to implement $first in an Angular ng-repeat to dynamically add a new table row

I am currently facing an issue with displaying a Google map for addresses in my Angular application. The problem seems to be related to the asynchronous nature of HTML and JS, but I am struggling to find a solution. The issue is that even though the map vi ...

Error message: "When using selenium-webdriver in JavaScript, the findElement method for <a> tags cannot be used as a function."&

Seeking the website URL for brand information from this website, I attempted to retrieve it using JavaScript in the console: document.getElementById('phone_number').getElementsByTagName('a')[1].getAttribute('href') However, ...

Utilizing global SCSS styles in a Vue project alongside distinct SCSS mixin and variable files

In the process of developing a Vue 3 app with scss, I have encountered a challenge. I have three separate stylesheet files - _mixins.scss, _variables.scss, and base.scss. To ensure that the mixins and variables are accessible in all components without manu ...

Issue occurs when a circle element is not following a div element on mouse

Currently, I have implemented some jQuery code that instructs a div named small-circle to track my cursor movement. I discovered how to accomplish this by referencing a thread on stack overflow. I made slight modifications to the script to suit my specifi ...

What is the process for retrieving matched information from a drop-down menu in HTML?

Is there a way to retrieve data from angularjs like this: This is the list of data I need to access: $scope.orderStatus = [ { os: 'Open', value: 1 }, { os: 'Completed', value: 2 }, { os:'Cancelled',value: 3 }, ...

Next.js allows for dynamic page routing using the `useState` hook to redirect users

In my Next.js project, I am using the useState hook to render different components based on the button a user clicks. The main page, called account.js in the application, contains the following code: // Importing react and getting components import React f ...

Trying to remove just one task, but ending up deleting all tasks instead in Vue 2 with Vuex 3

I've encountered an issue while using Vuex for my simple to-do app. When I attempt to delete a single to-do item, all of the todos are getting deleted instead. This behavior has left me puzzled as I am only deleting the one that matches the id of the ...