Vue.js: API request taking too long during mounted lifecycle

I am facing an issue with API data in my Vue js project. The page loads quickly but the data from the API takes more than 5 seconds to load. Strangely, the API response appears very fast in the console. I have implemented the API in a separate file called API services and created a class that contains all my APIs called BuildingService. However, when I call the API on mounted, it loads slowly. Can anyone provide assistance with this?

<script>
  import Vue from 'vue'
  import BuildingsService from "@/services/ApiService"

  Vue.use(VueClipboard)
  export default {
    data(){
      return{
buildings:[],

      }
    },
    name: 'icons',
    components: {
      BaseHeader
    },
  
    mounted:function(){
          BuildingsService.getBuildings().then((response) => {
      this.buildings = response.data.response;
      console.log(response.data.response,"dd");

    });
    }

   
   
          
      
  };
</script>
 
              <b-col lg="3" md="6"  v-for="(building, index) in buildings"
              :key="index" >
>{{building.building_number}}
   
              </b-col>
         

Answer №1

Try using the 'created' hook instead of 'mounted':

created() {
      BuildingsService.getBuildings().then((response) => {
      this.buildings = response.data.response;
      console.log(response.data.response,"dd");
    });
}

If you need more information, check out: this link

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

Running the command "npm run dev" generates a series of files named 0.js, 1.js, all the way up to 14.js within the

As a novice in the realm of Webpack, NPM, and VueJS, I find myself facing a perplexing issue. Despite my efforts to seek answers online, I remain stumped by the outcome when executing the command npm run dev in VueJS - wherein webpack generates 15 files l ...

Utilizing webpack for server-side development

I'm currently in the process of creating a node back-end service using express and I was thinking about incorporating webpack to bundle everything into a single file (although I'm not sure if this approach is correct as I'm still learning). ...

Tips and tricks for displaying JSON data in Angular 2.4.10

In my Angular project, I am facing an issue while trying to display specific JSON data instead of the entire JSON object. Scenario 1 : import { Component, OnInit } from '@angular/core'; import { HttpService } from 'app/http.service'; ...

What could be the reason for the empty array returned by the combinationSum function in Javascript?

The combinationSum function is returning an empty resultArr. When checking the ds array with console.log, it shows the correct answer, but for some reason, the final output array ends up being [[],[]]. var combinationSum = function(candidates, target) { ...

A guide to sorting JSON objects in Node.js

let data={ '0': { benchmark: null, hint: '', _id: '54fe44dadf0632654a000fbd', date: '2015-05-10T01:11:54.479Z' }, '1': { benchmark: null, hint: '', _id: ...

What is the correct way to utilize preloads and window.api calls in Electron?

I am struggling with implementing a render.js file to handle "api" calls from the JavaScript of the rendered HTML page. The new BrowserWindow function in main.js includes: webPreferences: { nodeIntegration: false, // default value after Electr ...

Stop procrastinating and take action before the JavaScript function concludes

Currently, I am experimenting with onkeydown events to capture the input value in a textarea, process it through a PHP file using Ajax post method, and display the result in an external div. However, the issue is that whenever a key is pressed, I am unable ...

Combining and arranging numerous items in a precise location in three.js

I am currently working on a web application using three.js with Angular and facing some challenges when trying to set the precise positions of objects. The requirement is to load various objects and position them in specific locations. In order to load di ...

Mastering the utilization of componentDidMount and componentDidUpdate within React.js: a comprehensive guide

I am facing an issue. I need to find an index based on a URL. All the relevant information is passed to the components correctly, but I encounter an error after loading: Cannot read property 'indexOf' of undefined The JSON data is being transmi ...

Utilizing Next.js named imports without server-side rendering

I am looking to update this code snippet to use next.js dynamic imports without server-side rendering (SSR) import { widget } from "./charting_library/charting_library"; Here is what I have tried so far const widget = dynamic(() => import(&qu ...

Populate DataTable with HTML content by fetching it through Ajax requests

My goal is to dynamically load the HTML returned from a controller into a div when a user clicks on a row in a table. Check out my code snippet below: // Add event listener for opening and closing details jQuery('#exRowTable tbody').on ...

By default, make the initial element of the list the selected option in an AngularJS select input

I'm running into an issue with setting the first element in my ng-repeat list within a select input. Here is the code snippet causing the problem: <div> <span >OF</span> <select ng-model="eclatementCourante.ordreFabricationId" n ...

Create artwork by drawing and adding text to an image before saving it

I am looking to enhance my website by adding a feature that allows users to draw on images hosted on the server. Additionally, I want users to have the ability to add text to the image and save their edits as a new picture. While it may seem like a simple ...

Building the logic context using NodeJS, SocketIO, and Express for development

Exploring the world of Express and SocketIO has been quite an eye-opener for me. It's surprising how most examples you come across simply involve transmitting a "Hello" directly from app.js. However, reality is far more complex than that. I've hi ...

Understanding text overflow in JavaScript and jQuery

I am facing an issue where the text in some columns of my table is breaking into two lines. I believe reducing the font size will resolve this problem, but I am unsure about where to start coding for this particular issue. If you have any ideas or sugges ...

Node is looking for a callback function, but instead received something that is undefined

When attempting to build a basic CRUD app in node js, an issue arises with the error message "Route.get() requires a callback function but got a [object Undefined]" specifically on the router.get("/:id", userController.getUser); line. Routes.js const expr ...

Ensure the links open in a new tab when using Firefox

I’m working on a new Firefox extension and I want to ensure that all links on a webpage open in a new tab. Any suggestions on how I can achieve this? ...

Updating Kendo by modifying the Angular model

While working on a project with Angular, I recently discovered the Kendo-Angular project available at . I successfully integrated Angular-Kendo into my project and it seems to be functioning well, except for updating models in the way I am accustomed to. ...

Tips for effectively utilizing innerHTML in this particular scenario

For an assignment, we were tasked with creating a Madlib game where users input words into textfields to replace certain words in a hidden paragraph within the HTML using JavaScript and CSS. The paragraph embedded in the HTML page is as follows: <span ...

boosting the maximum number of requests allowed

What can be done to increase the request limit if the user continues to hit rate limits? This is my current rate limiter setup: const Limiter = rateLimit({ windowMs: 10000, max: 5, standardHeaders: true, legacyHeaders: false, keyGenerator: funct ...