[Vuejs]-How to use foreach on fetch response in vue?

1👍

While fetch sends the request itself, the returned promise does not resolve when the server response is fully received.

The response object represents the stream of data. Because of that – res.json() returns another promise.

Try this:

fetch(url, options).then(response => response.json()).then(jsonResponse => {
  if (Array.isArray(jsonResponse)) {
    jsonResponse.forEach((work_order) => {
      //...
    });
  } else {
    throw Error('Server response was not an array');
  }
});

Leave a comment