How to implement axios in Vue to send a request, and then continue to perform the following operations after successfully obtaining the result?

I have a request here, the code is as follows

clipboard.png

ideally, it should first output that I am 1, and then output that I am 2

but in fact, it does output"I am 2 "first, followed by" I am 1"

.

do you guys know how to achieve this? I"m still a relatively new novice, but I don"t quite understand. I hope I can say it shallowly. Thank you

.
Jun.23,2022

ajax requests are asynchronous, so output 2 before 1

just put the actions you need to do into a successful callback


axios is asynchronous! Js is a single-threaded language. The browser only assigns one main thread to js to execute tasks (functions), but only one task at a time. These tasks form a queue of tasks waiting to be executed, and the asynchronous methods will not be executed until these tasks have been executed.
so execute 2 first, then 1! You can write console.log ('I am 3') console.log ('I am 4')
after console.log ('I am 2'). The result is 23 41


implement


getProjectForDetails() {
  **return new Promise((resolve, reject) => {**
    api.getProjectForDetails({"":""}).then(res => {
      this.dataList = res.dataList
      console.log('1')
      resolve(this.dataList)
    })
  **})**
},
  this.getProjectForDetails().then(res => {
    console.log('2')
  })
with promise or Async/Await.
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-1bd1b5b-5243a.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-1bd1b5b-5243a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?