[Vuejs]-Vue data value not updating for in function use

0👍

Might be a concurrency thing. Remember that the axios call is asynchronous so the loop will continue before the responses have been received.

So it could be the many responses are received at the same time and that loaded is then still 0 at that point. Looks like this won’t be the case. Apparently JavaScript will process callbacks one after the other.

I’m not sure how JavaScript handles concurrent increments though so I can’t exactly explain how that plays into effect here.

From your implementation, it looks like you’d want to turn the load function into an asynchronous function (using the async) keyword and then use the await before the axios call to ensure that you have received a response before making another request.

For interest’s sake, maybe have a look at your network tab and count how many requests are being made. I suspect there will be more requests made than this.article_count.

Leave a comment