for loop asynchronous axios requests cause inconsistent order

Requirements: The front end uses a for loop to traverse an interface to obtain data, and uses axios to request the address in the data

Problem: The order of each rendering of the front-end page is inconsistent

Reason: In the hook function created/setup, the order of multiple axios requests is not executed in the order in which the code is written. Because axios sends asynchronous requests, the time for each request to receive feedback is always different. It turns out that the for loop starts executing before the axios request has finished executing!

Solution: (adding await is the fastest solution)

 

Guess you like

Origin blog.csdn.net/qq_43532275/article/details/128948079