Axios è Async? [duplicare]
Aug 26 2020
Axios è asincrono da solo o è necessario per avvolgerlo attorno a una funzione asincrona? Ad esempio è questo asincrono:
function axios () {
axios.get()
}
O dovrei scriverlo in questo modo:
async function axios () {
await axios.get()
}
Grazie in anticipo
Risposte
2 RadicalEdward Aug 26 2020 at 08:43
Axiosrestituisce in promisemodo da poter utilizzare async awaito.then
asincrono attendono:
async function call() {
const { data } = await axios.get('api/test')
}
poi :
function call() {
axios.get('api/test').then(({data}) => {..operation here..})
}