How to perform elegant assignment in an Axios request?

var txt="33";
this.Axios.post("/api/Event/get_serve_name",data,{headers:{"Authorization":localStorage.gw_token}}).then(res=>{
                console.log(res)
                txt=res.data.HttpData.data[0].txt;
                
            })
return txt;

33
Aug.09,2021

you just deal with it as soon as you get the value in then. There is no need to assign values to external variables.

if you need to write Synchronize, ES6's async/await learn about

.
the stupidest callback assignment return goes out
async/await how long has it been out? learn

Promise

//
function getData(){
    return Axios.post(url).then(res=>res.data.HttpData.data[0].txt)
}
//
getData().then((txt)=>{
    console.log(txt)
})
//async 
async (){
    let txt = await getData();
    console.log(txt)
}

Callback

//
function getData(callback){
    Axios.post(url).then(res=>{
        callback(res.data.HttpData.data[0].txt)
    })
}
//
getData((txt)=>{
    console.log(txt)
})
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-1c278ee-3bc26.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-1c278ee-3bc26.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?