Delay problem of vue for Loop calling axios to create a new array based on the returned data

          let mindex = 0 ;
          let sum = this.multipleSelection.length ;
          let successNum = 0 ;

          for(const item of this.multipleSelection){
            jokeNumPP
            axios
              .get(MODULE_PATH.GAL_PATH + "/init-rule/init",{
                params:{
                  admCode:item.admCode,
                  eleCode:item.eleCode,
                  fiscal:this.fiscal
                }
              })
              .then(({ data,code }) => {
                flag = true
                if(code=="200"){
                  successNumPP  
                  console.log(successNum)   // 
                }else{
                  failNumPP;
                  console.log(failNum)
                }
              })
              .catch((err) => {
                this.$message({
                  type: "error",
                  message: err.msg
                });
              });
          }
          console.log(jokeNum)
          console.log(flag)
          console.log(this.successNum)     //
The

code, as above, makes a request in a for loop, and then saves the eligible data to a new variable according to the returned data, but at present, after the end of the for loop, the new variable is printed first, and the new variable is still empty. In the for loop condition judgment, it is the last print, asking for advice on how to get the correct new variable after the end of the loop?

Dec.06,2021

learn about the concurrency of multiple requests axios.all ()


this is an asynchronous request, you can learn about Event Loop
about this scenario, you can use

  

async/await learn about

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e496b4-592b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e496b4-592b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?