Encapsulate an axios method. Solve asynchronous problem

function logina (id, password) {
let url = "url";
let json = {

loginid: id,
password: password

};
let result = Post (url, json, null);
console.log (1, result);
return result;
}

function Post (api, post, headers) {
let result = false;
axios.post (api, post, {headers: headers})

.then((function(response) {
  console.log("post", response);
  return response;
}))
.catch(function(err) {
  console.log(err);
  return result;
});

}

The

code is shown above, and if successful, the result executed by console is undefined. After that, the corresponding data of post will be returned. How to make result return the data of response

Jun.24,2021

function Post(api, post, headerscallback) {
let result = false;
axios.post(api, post, { headers: headers })

.then((function(response) {
  console.log("post", response);
  callback(res);
  return response;
}))
.catch(function(err) {
  console.log(err);
  return result;
});
}

A successful callback returns res
post (apiurl, post, header,function (res) {

 console.log(res)

})

Menu