What is the best approach for looping through an array fetched using Ajax in Vue?

<div class="recipe-ingredients__container__functions paddings">
    <h5>Functions_</h5>
    <div class="foo" v-for="f in content.functions"></div>
</div>

When the HTML is rendered by Vue, the Ajax call is still in progress, so the content.functions data is not yet available. However, after the call is complete, I can see that the data has been correctly added using Vue Devtools in Chrome. Is there a simple way to trigger Vue to re-execute the v-for directive once the content.functions data becomes available?

Answer №1

To ensure your data remains up-to-date, initialize it as an empty array and only populate it once the AJAX request is successfully completed.

Here's an example:

data () {
  return {
    information: {
      details: []
    }
  }
},
created () {
  sendAjax().then(response => {
    this.information.details = response
  })
}

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

"Automatically insert a new row into the table if the cell loses focus and is not left

Can someone assist me with adding a table row dynamically when a cell is filled and the input focus is lost? My JavaScript skills are not strong. Here is a link to the form: JSFIDDLE <table class="table table-timesheet" ng-controller="TimesheetCtrl"> ...

Unable to expand the width of the video element

So I have encountered a situation like this The video displayed does not fully expand to the width of its containing element. This is what my HTML structure looks like - <div class="webcam"/> <div class="control-container"> </div> ...

Leveraging Node.js to establish a connection between two pug files

Recently, I decided to delve into the world of pug and JavaScript. However, I seem to be facing a small issue that I can't quite figure out on my own. My project involves creating multiple .pug files with various text content that I can navigate betwe ...

IE experiencing error due to ExternalInterface.call

My menu screen is made up of separate flash movie buttons, each supposed to call a JavaScript function when clicked. While this works perfectly in Firefox, I'm experiencing issues in IE7 where it fails to execute. Unfortunately, I don't have acce ...

Is it possible to activate the jQuery .click() function for a button with specific text?

Here's a dilemma I'm facing: $('.add_to_cart span:contains("Choose a Size")').click(function() { console.log("it has been clicked") }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></s ...

Modifying the page header content using JavaScript

There's this snippet of code that alters the image on another page: <div class="imgbx"> <button onclick="window.location.href='index.html?image=images/xr-black.jpg&tit=XR-black'" >Invisible ...

How to Obtain the Entire Form Using JQuery's ID Selector Instead of Just the Inner HTML

Currently, I am facing a dilemma with AJAX and CakePHP as I attempt to solve it by applying some clever solutions. Essentially, the issue lies in nesting forms - specifically, I have an element containing a form that is echoed within another form. This res ...

What is the best way to display input fields only if the previous input has a valid value?

My challenge involves creating a form with 3 to 10 text input fields. Initially, the form will display only 3 inputs (minimum). I am looking for an efficient way to dynamically show additional input rows as each previous row is filled out with a valid val ...

Utilizing Shared Variables among Functions within ES6 Classes

Exploring ES6 Syntax in Node.js has been an interesting journey for me. Starting off, I decided to create a basic class that sets up and returns an Express server - not entirely sure if it's ideal for production use. One challenge I encountered was a ...

Is using selectors a more effective way to retrieve computed data compared to using class methods?

When using react, redux, and reselect in a project, is it preferable to move all computable data from class methods to selectors and avoid mixing the use of both? Are there different concepts behind these approaches? class DocsListView { getOutdatedDocs ...

Utilizing Ajax with Django's Post Method

When I try to submit my form by pressing enter, the page only displays serialized data from the form and nothing else. The console shows this error: Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:80 ...

Efficient ways to temporarily store form data in React JS

When filling out a registration form and clicking on the terms and conditions link, the page redirects to that content. Upon returning to the registration page, all fields are empty and need to be filled in again from scratch. I am looking for a way to ha ...

showing a loading spinner while sending an ajax request, patiently awaiting the response, and preventing any further interactions on the page

On my page, I am utilizing multiple ajax calls to load specific parts of the response. However, I need to display a spinner on the section where the ajax call is being made to indicate that content is loading. Is there a way to create a universal method th ...

Troubleshooting Highcharts container selection problem on Nexus 7 running version 4.2.1

Having a problem with Highcharts on my Nexus 7. When I touch the chart, the entire thing gets selected with a blue overlay, but this doesn't happen on other devices like the Nexus 4. Even when I try accessing demos from Highcharts website, the issue ...

Breaking down an RxJS observable sequence into various outputs

Can a single observable flux be split into multiple other observables? For example, I have a form that users can submit. The submit action is captured by an observable, and a validator is triggered upon submission. submitAction.forEach(validate) However ...

Node.JS is configured to hold onto localhost and will not release it

After successfully deploying one application built in Node locally, I am now facing an issue with another application. Whenever I try to start node (v5) with express (v4.13) on my localhost, it just hangs without establishing any connections. I am using a ...

Why is the deployed Express server failing to establish a session?

After deploying a node express server on Digital Ocean, I encountered an issue where the session was not being created. To address this, I implemented a store to prevent memory leak and included app.set('trust proxy', 1) before initializing the s ...

dynamically passing arguments to an onclick function

I am experiencing an issue with the following HTML element that has an onclick() function dynamically attached. When trying to call the function, it throws an error stating that "ST" is not defined. The variable passed as name is something like "ST-123". C ...

Failure to achieve success with jQuery Ajax

success in my AJAX call is not triggering at all, leaving me puzzled as to why. None of the alerts specified in the AJAX file are appearing. The form: <form onsubmit="check_reg();return false;" method="post" name="reg_form" id="reg"> <label ...

Having trouble figuring out why I am unable to call a function on the response in Vue using Axios

I've encountered an issue while updating the code of a previous developer. The code is giving me an error that says: Uncaught (in promise) TypeError: failedCallback is not a function The problematic function looks like this: export default { get( ...