How can new data be passed to props within the async fetch() function in Nuxt.js?

Hello, is it possible to dynamically update props inside an async fetch after the page has loaded? Here is an example:

props: {
  products: {
   type: Array,
   required:true
 }
}
async fetch() {
let data = this.products
 // Perform data processing for display....
}

methods: {
  updateProducts() {
    return this.products.push(newdata);
  }
}

How can I update `this.products` within the `async fetch` function with new data?

Answer №1

If you need to trigger a fetch hook again, consider using this.$fetch(). However, in your specific situation, this may not be necessary. Utilizing a watch function or emitting a value to the parent component could suffice.

For a code example, check out this snippet: How to implement lazy loading in Vue.js?

In general, it's recommended to move your logic to a regular method like processData.

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

Achieve maximum height with background images

Having trouble with responsiveness on my box containing a background image. I am aiming for the box to adjust its height based on the background image, as I have set the background-size attribute to auto. html: <div class="index_boxs" id="discover_win ...

Unable to interpret data output from PHP file using AJAX

I'm struggling with passing a form variable to an ajax request in my php file, and then displaying the php file's content in a div. Here is my primary code snippet: <div> <form name="zipform"> <p style="color:#ccccc ...

What is the best way to attach information to a chart prior to the jquery dialog box appearing?

I am currently working on a web application that interacts with an Azure database. The goal is to create a graph based on user selections from a radio list and two inputted time parameters. The intention is to showcase this graph in a jQuery dialog box tha ...

Is there a way to handle the ajax request only when necessary, instead of processing it every few seconds?

Currently, I am working on an AJAX chat system using PHP, MySQL, JavaScript, and AJAX. I have a piece of code that retrieves all chat messages within a div using AJAX, with the function running every 2 seconds. My issue lies in the fact that the div autom ...

How to Alter Button Color upon Click in React with Bootstrap?

I'm working on implementing a thumbs up and thumbs down feature similar to Reddit's upvote and downvote system. The goal is to change the color of the object to green when the thumbs up is clicked and to red when the thumbs down is clicked. How ...

Extract information from an array located inside a nested object

My aim is to calculate the length of the skills array for each user individually. To begin, I have this JSON data: const txt = `{ "Alex": { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" da ...

Exploring the Force-Directed Graph Demo on bl.ocks.org

I don't have much expertise in javascript, jquery, or json. My objective is to create a graph using the force-directed graph example from bl.ock.us. 1) I wrote a python script to generate the necessary json data. 2) I noticed others were us ...

Is there a way to retrieve the final word following a unique character?

Currently, I have this: \- (.*) When analyzing the text below: September 2014 - Media I am trying to extract "Media", but instead I am retrieving "- Media" ...

Angular Search Panel

I'm having trouble with the Angular Search box not working when I try to run it locally on my computer. The same code works perfectly fine on platforms like codepen, plunker, and jsfiddle. Can someone help me figure out what's going wrong? .ex ...

Executing a npm script (script.js) with custom arguments - a step-by-step guide

I'm considering creating a setup similar to lodash custom builds. Basically, I want to allow users to input a command like: lodash category=collection,function This would create a custom module with the specified category. I've been looking in ...

Dealing with the outcome of a synchronous AJAX request and displaying or concealing a div based on the result's value

I am attempting to run a JavaScript function that checks for internet connectivity status. If the user is connected to the internet, I do not want anything to happen on screen. However, if the connection is lost, I would like to display a div element. The ...

The restify.bodyParser() function does not seem to be functioning correctly, as the req object is appearing

When working with restify, I've noticed that the request object is always empty when making HTTP POST calls. Does anyone have any ideas on why this might be happening? Thanks ...

Styling and Script Files on a JQuery Mobile Website

Is it necessary to include CSS and JS files in every HTML page for a mobile site developed with JQueryMobile? <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> <script src="http://code.jquery.com/jqu ...

Loading static images in Vue components within a Django application

I am currently using a combination of Laravel Mix, Django, and Vue in my project. I want to be able to display static images within my Vue component that are stored in the 'static/img' folder. To begin with, I have created an alias in the Webpac ...

Utilizing the json_encode() function in PHP and JSON.parse() method in JavaScript for handling file data interchange

Utilizing json_encode() in PHP to store an array in a file, then leveraging JSON.parse() in JavaScript on the client side to read the json encoded file and pass it as an array to a sorting algorithm: The result of my json_encode() operation in the ...

How to deselect a checkbox in next.js when another one is selected

I'm looking to create a navigation system where clicking on a button scrolls to a specific section. However, I'm wondering how to deselect three inputs when one is selected in next.js using the code below. Do I need to modify each menu item indiv ...

Demolishing Datatable for Repurposing

I need help with a button on a Data table labeled "Go Back" that I want to clear and prepare the table for reuse. So far, I have used the clear() and destroy() methods successfully, but it seems to stop working after multiple clicks. Is there a way to con ...

Display or conceal a div when hovering over dropdown menu choices

$('#dropdown-list').on('change',function(){ if( $(this).val()==="option 1" ){ $("#diva").hide() } else { $("#divb").show() } }); The code above is being used to hide or show a div based on a dropdown selection, which is f ...

Updating the state of a nested array using React Hooks

After spending some time working with React Hooks, my main struggle has been dealing with arrays. Currently, I am developing a registration form for teams. Each team consists of a list of players (an array of strings). The goal is to allow users to add t ...

The properties are not appearing on the screen nor in the React Development Tools

Having difficulties grasping React props and mapping data from an array? Struggling to get the props to show up on your Card component, or display in React dev tools? It's unclear where the mistake lies. Seeking assistance to pinpoint the issue. Also ...